Search in sources :

Example 11 with Transformation

use of org.opentosca.toscana.core.transformation.Transformation in project TOSCAna by StuPro-TOSCAna.

the class TransformationControllerTest method mockTransformationService.

private void mockTransformationService() {
    transformationService = mock(TransformationService.class);
    when(transformationService.createTransformation(any(Csar.class), any(Platform.class))).then(iom -> {
        Csar csar = (Csar) iom.getArguments()[0];
        Platform platform = (Platform) iom.getArguments()[1];
        Transformation t = new TransformationImpl(csar, platform, logMock(), modelMock());
        csar.getTransformations().put(platform.id, t);
        return t;
    });
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) TransformationImpl(org.opentosca.toscana.core.transformation.TransformationImpl) Transformation(org.opentosca.toscana.core.transformation.Transformation) Platform(org.opentosca.toscana.core.transformation.platform.Platform) TransformationService(org.opentosca.toscana.core.transformation.TransformationService)

Example 12 with Transformation

use of org.opentosca.toscana.core.transformation.Transformation in project TOSCAna by StuPro-TOSCAna.

the class CsarFilesystemDaoTest method returnedCsarHasPopulatedTransformations.

@Test
public void returnedCsarHasPopulatedTransformations() {
    // test whether CsarDao calls TransformationDao internally to populate list of transformations
    String identifier = createFakeCsarDirectories(1)[0];
    Csar csar = new CsarImpl(new File(""), identifier, logMock());
    csarDao = new CsarFilesystemDao(preferences, transformationDao);
    List<Transformation> transformations = TestPlugins.PLATFORMS.stream().map(platform -> new TransformationImpl(csar, platform, logMock(), modelMock())).collect(Collectors.toList());
    when(transformationDao.find(any())).thenReturn(transformations);
    csarDao.init();
    Optional<Csar> result = csarDao.find(identifier);
    assertTrue(result.isPresent());
    assertEquals(TestPlugins.PLATFORMS.size(), result.get().getTransformations().size());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Mock(org.mockito.Mock) Transformation(org.opentosca.toscana.core.transformation.Transformation) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) TestPlugins(org.opentosca.toscana.core.testdata.TestPlugins) File(java.io.File) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) TransformationImpl(org.opentosca.toscana.core.transformation.TransformationImpl) List(java.util.List) Preferences(org.opentosca.toscana.core.util.Preferences) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) TransformationDao(org.opentosca.toscana.core.transformation.TransformationDao) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) TestCsars(org.opentosca.toscana.core.testdata.TestCsars) Before(org.junit.Before) TransformationImpl(org.opentosca.toscana.core.transformation.TransformationImpl) Transformation(org.opentosca.toscana.core.transformation.Transformation) File(java.io.File) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 13 with Transformation

use of org.opentosca.toscana.core.transformation.Transformation in project TOSCAna by StuPro-TOSCAna.

the class TransformationControllerTest method preInitNonCreationTests.

// </editor-fold>
// <editor-fold desc="Util Methods">
public List<Transformation> preInitNonCreationTests() throws PlatformNotFoundException {
    // add a transformation
    Optional<Csar> csar = csarService.getCsar(VALID_CSAR_NAME);
    assertTrue(csar.isPresent());
    String[] pnames = { VALID_PLATFORM_NAME, SECOND_VALID_PLATFORM_NAME };
    List<Transformation> transformations = new ArrayList<>();
    for (String pname : pnames) {
        LogEntry entry = new LogEntry(0, "Test Context", "Test Message", Level.DEBUG);
        Log mockLog = logMock();
        when(mockLog.getLogEntries(0)).thenReturn(Collections.singletonList(entry));
        Transformation transformation = new TransformationImpl(csar.get(), platformService.findPlatformById(pname).get(), mockLog, modelMock());
        transformation = spy(transformation);
        transformations.add(transformation);
        csar.get().getTransformations().put(pname, transformation);
    }
    return transformations;
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) TransformationImpl(org.opentosca.toscana.core.transformation.TransformationImpl) Transformation(org.opentosca.toscana.core.transformation.Transformation) Log(org.opentosca.toscana.core.transformation.logging.Log) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LogEntry(org.opentosca.toscana.core.transformation.logging.LogEntry)

Example 14 with Transformation

use of org.opentosca.toscana.core.transformation.Transformation in project TOSCAna by StuPro-TOSCAna.

the class TransformationControllerTest method testGetOutputsInvalidState.

@Test
public void testGetOutputsInvalidState() throws Exception {
    List<Transformation> transformations = preInitNonCreationTests();
    Transformation t = transformations.get(0);
    when(t.getState()).thenReturn(TransformationState.TRANSFORMING);
    mvc.perform(get(GET_OUTPUT_URL)).andDo(print()).andExpect(status().is(400)).andReturn();
}
Also used : Transformation(org.opentosca.toscana.core.transformation.Transformation) Test(org.junit.Test) BaseSpringTest(org.opentosca.toscana.core.BaseSpringTest)

Example 15 with Transformation

use of org.opentosca.toscana.core.transformation.Transformation in project TOSCAna by StuPro-TOSCAna.

the class TransformationControllerTest method testGetOutputsEmptyOutputs.

@Test
public void testGetOutputsEmptyOutputs() throws Exception {
    List<Transformation> transformations = preInitNonCreationTests();
    Transformation t = transformations.get(0);
    when(t.getState()).thenReturn(TransformationState.DONE);
    when(t.getOutputs()).thenReturn(new ArrayList<>());
    mvc.perform(get(GET_OUTPUT_URL)).andDo(print()).andExpect(status().is(200)).andExpect(jsonPath("$.outputs").isArray()).andExpect(jsonPath("$.links[0].href").value("http://localhost/api/csars/kubernetes-cluster/transformations/p-a/outputs")).andReturn();
}
Also used : Transformation(org.opentosca.toscana.core.transformation.Transformation) Test(org.junit.Test) BaseSpringTest(org.opentosca.toscana.core.BaseSpringTest)

Aggregations

Transformation (org.opentosca.toscana.core.transformation.Transformation)22 Csar (org.opentosca.toscana.core.csar.Csar)16 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 TransformationImpl (org.opentosca.toscana.core.transformation.TransformationImpl)8 Test (org.junit.Test)6 File (java.io.File)4 IllegalTransformationStateException (org.opentosca.toscana.api.exceptions.IllegalTransformationStateException)4 BaseSpringTest (org.opentosca.toscana.core.BaseSpringTest)4 CsarImpl (org.opentosca.toscana.core.csar.CsarImpl)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)3 PropertyInstance (org.opentosca.toscana.core.transformation.properties.PropertyInstance)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 GetInputsResponse (org.opentosca.toscana.api.model.GetInputsResponse)2