Search in sources :

Example 1 with ComposeEnvironment

use of org.eclipse.che.plugin.docker.compose.ComposeEnvironment in project che by eclipse.

the class EnvironmentDeserializerTest method testCorrectContentParsing.

@Test(dataProvider = "correctContentTestData")
public void testCorrectContentParsing(String content, Map<String, String> expected) throws ServerException {
    ComposeEnvironment cheServicesEnvironment = parser.parse(content, "application/x-yaml");
    // then
    assertEquals(cheServicesEnvironment.getServices().get("dev-machine").getEnvironment(), expected);
}
Also used : ComposeEnvironment(org.eclipse.che.plugin.docker.compose.ComposeEnvironment) Test(org.testng.annotations.Test)

Example 2 with ComposeEnvironment

use of org.eclipse.che.plugin.docker.compose.ComposeEnvironment in project che by eclipse.

the class ComposeEnvironmentParser method parse.

/**
     * Parses compose file from {@link Environment} into {@link CheServicesEnvironmentImpl}.
     *
     * @param environment
     *         environment with {@link EnvironmentRecipe} to parse.
     *         {@link EnvironmentRecipe} contains {@link CheServicesEnvironmentImpl} definition.
     * @throws IllegalArgumentException
     *         when environment or environment recipe is invalid
     * @throws ServerException
     *         when environment recipe can not be retrieved
     */
@Override
public CheServicesEnvironmentImpl parse(Environment environment) throws ServerException {
    requireNonNull(environment, "Environment should not be null");
    EnvironmentRecipe recipe = environment.getRecipe();
    requireNonNull(environment.getRecipe(), "Environment recipe should not be null");
    String content = getContentOfRecipe(recipe);
    ComposeEnvironment composeEnvironment = parse(content, recipe.getContentType());
    return asCheEnvironment(composeEnvironment);
}
Also used : ComposeEnvironment(org.eclipse.che.plugin.docker.compose.ComposeEnvironment) EnvironmentRecipe(org.eclipse.che.api.core.model.workspace.EnvironmentRecipe)

Example 3 with ComposeEnvironment

use of org.eclipse.che.plugin.docker.compose.ComposeEnvironment in project che by eclipse.

the class BuildContextTest method shouldNotParseBuildArgsWhenNotProvided.

@Test
public void shouldNotParseBuildArgsWhenNotProvided() throws ServerException {
    // given
    String recipeContent = "services:\n" + " dev-machine:\n" + "  build:\n" + "   context: .\n";
    // when
    ComposeEnvironment composeEnvironment = parser.parse(recipeContent, "application/x-yaml");
    // then
    assertEquals(Collections.emptyMap(), composeEnvironment.getServices().get("dev-machine").getBuild().getArgs());
}
Also used : ComposeEnvironment(org.eclipse.che.plugin.docker.compose.ComposeEnvironment) Test(org.testng.annotations.Test)

Example 4 with ComposeEnvironment

use of org.eclipse.che.plugin.docker.compose.ComposeEnvironment in project che by eclipse.

the class BuildContextTest method shouldParseBuildArgsWhenProvided.

@Test
public void shouldParseBuildArgsWhenProvided() throws ServerException {
    // given
    String recipeContent = "services:\n" + " dev-machine:\n" + "  build:\n" + "   context: .\n" + "   args:\n" + "    buildno: 1\n" + "    password: secret\n";
    Map<String, String> expected = new HashMap<String, String>() {

        {
            put("buildno", "1");
            put("password", "secret");
        }
    };
    // when
    ComposeEnvironment composeEnvironment = parser.parse(recipeContent, "application/x-yaml");
    // then
    assertEquals(composeEnvironment.getServices().get("dev-machine").getBuild().getArgs(), expected);
}
Also used : HashMap(java.util.HashMap) ComposeEnvironment(org.eclipse.che.plugin.docker.compose.ComposeEnvironment) Test(org.testng.annotations.Test)

Example 5 with ComposeEnvironment

use of org.eclipse.che.plugin.docker.compose.ComposeEnvironment in project che by eclipse.

the class CommandDeserializerTest method composeServiceCommandShouldBeParsedSuccessfully.

@Test(dataProvider = "validCommand")
public void composeServiceCommandShouldBeParsedSuccessfully(String command, List<String> commandWords, int commandNumberOfWords) throws Exception {
    String content = format(RECIPE_WITHOUT_COMMAND_VALUE, command);
    ComposeEnvironment composeEnvironment = composeEnvironmentParser.parse(content, "application/x-yaml");
    assertEquals(composeEnvironment.getServices().size(), 1);
    ComposeServiceImpl service = composeEnvironment.getServices().get("machine1");
    assertEquals(service.getImage(), "codenvy/mysql");
    assertEquals(service.getMemLimit().longValue(), 2147483648L);
    Map<String, String> environment = service.getEnvironment();
    assertEquals(environment.size(), 2);
    assertEquals(environment.get("MYSQL_USER"), "petclinic");
    assertEquals(environment.get("MYSQL_PASSWORD"), "password");
    assertTrue(service.getExpose().containsAll(asList("4403", "5502")));
    assertTrue(service.getCommand().containsAll(commandWords));
    assertEquals(service.getCommand().size(), commandNumberOfWords);
}
Also used : ComposeEnvironment(org.eclipse.che.plugin.docker.compose.ComposeEnvironment) ComposeServiceImpl(org.eclipse.che.plugin.docker.compose.ComposeServiceImpl) Test(org.testng.annotations.Test)

Aggregations

ComposeEnvironment (org.eclipse.che.plugin.docker.compose.ComposeEnvironment)6 Test (org.testng.annotations.Test)4 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 EnvironmentRecipe (org.eclipse.che.api.core.model.workspace.EnvironmentRecipe)1 ComposeServiceImpl (org.eclipse.che.plugin.docker.compose.ComposeServiceImpl)1