/**
 * Copyright 1&1 Internet AG, https://github.com/1and1/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.oneandone.stool.setup;

import net.oneandone.stool.configuration.StoolConfiguration;
import net.oneandone.stool.extensions.ExtensionsFactory;
import net.oneandone.stool.util.Session;
import net.oneandone.sushi.cli.Console;
import net.oneandone.sushi.fs.World;
import net.oneandone.sushi.fs.file.FileNode;
import org.junit.Test;

import static org.junit.Assert.assertNotNull;

public class LibTest {
    @Test
    public void create() throws Exception {
        Console console;
        FileNode dir;
        Lib lib;
        String group;

        console = Console.create(new World());
        dir = console.world.getTemp().createTempDirectory();
        group = dir.getGroup().toString();
        dir.deleteDirectory();
        lib = new Lib(console, dir, group, null);
        lib.create();
        assertNotNull(StoolConfiguration.load(Session.gson(console.world, ExtensionsFactory.create(console.world)), dir));
    }

    @Test
    public void upgrade() throws Exception {
        Console console;
        FileNode dir;
        Lib lib;
        String group;

        console = Console.create(new World());
        dir = console.world.getTemp().createTempDirectory();
        dir.deleteDirectory();
        console.world.guessProjectHome(getClass()).join("src/test/upgrade").copy(dir);
        group = dir.getGroup().toString();
        lib = new Lib(console, dir, group, null);
        lib.upgrade("3.3.4");
    }
}

@@ -956,16 +956,61 @@
 .Test;%0A%0A
+import static org.junit.Assert.assertEquals;%0A
 import s
@@ -1728,32 +1728,66 @@
    String group;
+%0A        StoolConfiguration stool;
 %0A%0A        consol
@@ -2121,16 +2121,196 @@
 .3.4%22);%0A
+        stool = StoolConfiguration.load(Session.gson(console.world, ExtensionsFactory.create(console.world)), dir);%0A        assertEquals(%22cpgem1.ciso.server.lan%22, stool.hostname);%0A
     %7D%0A%7D%0A

upgrade test