Search in sources :

Example 6 with TransformationImpl

use of org.opentosca.toscana.core.transformation.TransformationImpl 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 7 with TransformationImpl

use of org.opentosca.toscana.core.transformation.TransformationImpl 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 8 with TransformationImpl

use of org.opentosca.toscana.core.transformation.TransformationImpl 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 9 with TransformationImpl

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

the class BaseTransformTest method initContext.

/**
 *     initializes the transformation context
 */
protected TransformationContext initContext() throws Exception {
    Csar csar = new CsarImpl(tmpdir, "csarId", logMock());
    Transformation t = new TransformationImpl(csar, plugin.getPlatform(), logMock(), model);
    Transformation transformation = spy(t);
    when(transformation.getInputs()).thenReturn(inputs);
    return new TransformationContext(transformation, workingDir);
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) TransformationImpl(org.opentosca.toscana.core.transformation.TransformationImpl) Transformation(org.opentosca.toscana.core.transformation.Transformation) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext)

Aggregations

TransformationImpl (org.opentosca.toscana.core.transformation.TransformationImpl)9 Transformation (org.opentosca.toscana.core.transformation.Transformation)8 Csar (org.opentosca.toscana.core.csar.Csar)7 CsarImpl (org.opentosca.toscana.core.csar.CsarImpl)5 File (java.io.File)4 Before (org.junit.Before)3 Test (org.junit.Test)3 TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)3 Platform (org.opentosca.toscana.core.transformation.platform.Platform)3 HashSet (java.util.HashSet)2 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)2 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Assert.assertEquals (org.junit.Assert.assertEquals)1