Search in sources :

Example 1 with BlueprintV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request in project cloudbreak by hortonworks.

the class DefaulBlueprintCacheTest method testOnlyReleasedBps.

@Test
public void testOnlyReleasedBps() throws IOException {
    // GIVEN
    Blueprint bp1 = new Blueprint();
    bp1.setName("bp1");
    bp1.setBlueprintText("txt");
    bp1.setStackName("stckn");
    bp1.setStackType("stckt");
    bp1.setStackVersion("stckv");
    String bp1JsonString = "{\"inputs\":[],\"blueprint\":{\"Blueprints\":{\"blueprint_name\":\"bp1\"}}}";
    JsonNode bpText1 = JsonUtil.readTree(bp1JsonString);
    when(blueprintUtils.convertStringToJsonNode(any())).thenReturn(bpText1);
    Blueprint bp2 = new Blueprint();
    bp2.setName("bp2");
    bp2.setBlueprintText("txt");
    bp2.setStackName("stckn");
    bp2.setStackType("stckt");
    bp2.setStackVersion("stckv");
    String bp2JsonString = "{\"inputs\":[],\"blueprint\":{\"Blueprints\":{\"blueprint_name\":\"bp2\"}}}";
    JsonNode bpText2 = JsonUtil.readTree(bp2JsonString);
    when(blueprintUtils.convertStringToJsonNode(any())).thenReturn(bpText2);
    when(blueprintUtils.isBlueprintNamePreConfigured(anyString(), any())).thenReturn(true);
    when(blueprintEntities.getDefaults()).thenReturn(Map.of("7.0.2", "Description2=bp2;Description1=bp1"));
    when(converter.convert(any(BlueprintV4Request.class))).thenAnswer(invocation -> {
        BlueprintV4Request request = invocation.getArgument(0);
        if ("Description1".equalsIgnoreCase(request.getName())) {
            return bp1;
        }
        return bp2;
    });
    // WHEN
    underTest.loadBlueprintsFromFile();
    Map<String, BlueprintFile> defaultBlueprints = underTest.defaultBlueprints();
    // WHEN
    assertEquals(2L, defaultBlueprints.size());
    assertEquals("Description1", defaultBlueprints.get("bp1").getDescription());
    assertEquals("Description2", defaultBlueprints.get("bp2").getDescription());
}
Also used : BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with BlueprintV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request in project cloudbreak by hortonworks.

the class BlueprintV4RequestToBlueprintConverterTest method rejectsBuiltinWithoutContent.

@Test
public void rejectsBuiltinWithoutContent() {
    BlueprintV4Request request = new BlueprintV4Request();
    request.setBlueprint("{ \"blueprint\": {}");
    thrown.expect(BadRequestException.class);
    thrown.expectMessage("Invalid cluster template: Failed to parse JSON.");
    underTest.convert(request);
}
Also used : BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) Test(org.junit.Test) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest)

Example 3 with BlueprintV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request in project cloudbreak by hortonworks.

the class BlueprintV4RequestToBlueprintConverterTest method testConvertShouldThrowExceptionWhenTheBlueprintJsonIsInvalid.

@Test(expected = BadRequestException.class)
public void testConvertShouldThrowExceptionWhenTheBlueprintJsonIsInvalid() {
    BlueprintV4Request request = new BlueprintV4Request();
    String blueprint = "{}";
    request.setBlueprint(blueprint);
    when(jsonHelper.createJsonFromString(blueprint)).thenThrow(new CloudbreakApiException("Invalid Json"));
    underTest.convert(request);
}
Also used : BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) CloudbreakApiException(com.sequenceiq.cloudbreak.json.CloudbreakApiException) Test(org.junit.Test) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest)

Example 4 with BlueprintV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request in project cloudbreak by hortonworks.

the class BlueprintToBlueprintV4RequestConverter method convert.

public BlueprintV4Request convert(Blueprint source) {
    BlueprintV4Request blueprintV4Request = new BlueprintV4Request();
    blueprintV4Request.setName(source.getName());
    blueprintV4Request.setDescription(source.getDescription());
    blueprintV4Request.setBlueprint(source.getBlueprintText());
    blueprintV4Request.setDescription(source.getDescription());
    return blueprintV4Request;
}
Also used : BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request)

Example 5 with BlueprintV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request in project cloudbreak by hortonworks.

the class DefaulBlueprintCacheTest method testLoadBlueprintsFromFileWithUpgradeOptions.

@Test
public void testLoadBlueprintsFromFileWithUpgradeOptions() throws IOException {
    // GIVEN
    Blueprint bp1 = new Blueprint();
    bp1.setName("bp1");
    bp1.setBlueprintText("txt");
    bp1.setStackName("stckn");
    bp1.setStackType("stckt");
    bp1.setStackVersion("stckv");
    String bp1JsonString = "{\"description\":\"7.2.10 - Data Engineering\",\"blueprint\":{\"cdhVersion\":\"7.2.10\",\"displayName\":\"dataengineering\"," + "\"blueprintUpgradeOption\":\"DISABLED\"}}";
    JsonNode bpText1 = JsonUtil.readTree(bp1JsonString);
    when(blueprintUtils.convertStringToJsonNode(any())).thenReturn(bpText1);
    when(blueprintEntities.getDefaults()).thenReturn(Map.of("7.2.10", "Description1=bp1"));
    when(blueprintUtils.isBlueprintNamePreConfigured(anyString(), any())).thenReturn(true);
    when(converter.convert(any(BlueprintV4Request.class))).thenAnswer(invocation -> {
        BlueprintV4Request request = invocation.getArgument(0);
        return bp1;
    });
    underTest.loadBlueprintsFromFile();
    Map<String, BlueprintFile> defaultBlueprints = underTest.defaultBlueprints();
    assertEquals(1L, defaultBlueprints.size());
    assertEquals("7.2.10 - Data Engineering", defaultBlueprints.get("bp1").getDescription());
    assertEquals(BlueprintUpgradeOption.DISABLED, defaultBlueprints.get("bp1").getBlueprintUpgradeOption());
}
Also used : BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

BlueprintV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request)10 Test (org.junit.Test)7 AbstractJsonConverterTest (com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest)5 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 BlueprintFile (com.sequenceiq.cloudbreak.domain.BlueprintFile)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Json (com.sequenceiq.cloudbreak.common.json.Json)1 CloudbreakApiException (com.sequenceiq.cloudbreak.json.CloudbreakApiException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 PostConstruct (javax.annotation.PostConstruct)1 Before (org.junit.Before)1 LocalValidatorFactoryBean (org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)1