Search in sources :

Example 6 with CsarImpl

use of org.opentosca.toscana.core.csar.CsarImpl in project TOSCAna by StuPro-TOSCAna.

the class TransformerHealthIndicatorTest method initTestEnvironment.

private void initTestEnvironment() {
    // Create Dummy Csar
    // DummyCsar csar = new DummyCsar("test");
    Csar csar = new CsarImpl(new File(""), MOCK_CSAR_NAME, logMock());
    csar = spy(csar);
    Map<String, Transformation> transformations = new HashMap<>();
    Set<Platform> platformSet = new HashSet<>();
    for (Object[] d : MOCK_DATA) {
        // Initialize transformation Mock
        Transformation transformation = new TransformationImpl(csar, (Platform) d[0], logMock(), modelMock());
        transformation.setState((TransformationState) d[1]);
        transformations.put(((Platform) d[0]).id, transformation);
        // Add platform to supported platform list
        platformSet.add((Platform) d[0]);
    }
    // Add Transformations to csar
    when(csar.getTransformations()).thenReturn(transformations);
    // Platforms
    when(pluginService.getSupportedPlatforms()).thenReturn(platformSet);
    // Repository
    when(repository.findAll()).thenReturn(Collections.singletonList(csar));
}
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) HashMap(java.util.HashMap) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) File(java.io.File) HashSet(java.util.HashSet)

Example 7 with CsarImpl

use of org.opentosca.toscana.core.csar.CsarImpl in project TOSCAna by StuPro-TOSCAna.

the class TransformationControllerTest method mockCsarService.

private void mockCsarService() {
    csarService = mock(CsarService.class);
    List<Csar> csars = new ArrayList<>();
    when(csarService.getCsar(anyString())).thenReturn(Optional.empty());
    for (String name : CSAR_NAMES) {
        Csar csar = new CsarImpl(TestCsars.Testing.EMPTY_TOPOLOGY_TEMPLATE, name, logMock());
        when(csarService.getCsar(name)).thenReturn(Optional.of(csar));
    }
    when(csarService.getCsars()).thenReturn(csars);
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) CsarService(org.opentosca.toscana.core.csar.CsarService)

Example 8 with CsarImpl

use of org.opentosca.toscana.core.csar.CsarImpl in project TOSCAna by StuPro-TOSCAna.

the class CsarControllerTest method setUp.

@Before
public void setUp() throws Exception {
    List<Csar> mockedCsars = new ArrayList<>();
    service = mock(CsarService.class);
    when(service.getCsars()).thenReturn(mockedCsars);
    when(service.getCsar(anyString())).thenReturn(Optional.empty());
    for (String name : MOCK_CSAR_NAMES) {
        LogEntry entry = new LogEntry(0, "TestContext", "Test Message", Level.DEBUG);
        Log mockLog = logMock();
        when(mockLog.getLogEntries(0)).thenReturn(Collections.singletonList(entry));
        Csar csar = spy(new CsarImpl(new File(""), name, mockLog));
        when(service.getCsar(name)).thenReturn(Optional.of(csar));
        mockedCsars.add(csar);
    }
    when(service.submitCsar(anyString(), any(InputStream.class))).thenAnswer(iom -> {
        // Check if the csar is already known
        if (service.getCsar(iom.getArguments()[0].toString()).isPresent()) {
            return null;
        }
        // Copy "sent" data into a byte array
        InputStream in = (InputStream) iom.getArguments()[1];
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(in, out);
        dataRead = out.toByteArray();
        // Create Csar Mock
        return new CsarImpl(new File(""), iom.getArguments()[0].toString(), logMock());
    });
    CsarController controller = new CsarController(service);
    mvc = MockMvcBuilders.standaloneSetup(controller).build();
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) Log(org.opentosca.toscana.core.transformation.logging.Log) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CsarService(org.opentosca.toscana.core.csar.CsarService) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) File(java.io.File) LogEntry(org.opentosca.toscana.core.transformation.logging.LogEntry) Before(org.junit.Before)

Example 9 with CsarImpl

use of org.opentosca.toscana.core.csar.CsarImpl in project TOSCAna by StuPro-TOSCAna.

the class TransformationDaoUnitTest method setUp.

@Before
public void setUp() throws IOException, InvalidCsarException {
    when(platformService.findPlatformById(PLATFORM1.id)).thenReturn(Optional.ofNullable(PLATFORM1));
    when(preferences.getDataDir()).thenReturn(tmpdir);
    Log log = logMock();
    csar = spy(new CsarImpl(new File(""), "csarIdentifier", log));
    doReturn(new File("")).when(csar).getTemplate();
    File csarTransformationDir = new File(tmpdir, "transformationDir");
    csarTransformationDir.mkdir();
    when(csarDao.getTransformationsDir(csar)).thenReturn(csarTransformationDir);
    platformDir = new File(csarTransformationDir, PLATFORM1.id);
    platformDir.mkdir();
    File someTransformationFile = new File(platformDir, "some-file");
    someTransformationFile.createNewFile();
    EffectiveModelFactory modelFactory = mock(EffectiveModelFactory.class);
    EffectiveModel model = modelMock();
    when(modelFactory.create(any(File.class), any(Log.class))).thenReturn(model);
    dao = new TransformationFilesystemDao(platformService, modelFactory);
    dao.setCsarDao(csarDao);
}
Also used : Log(org.opentosca.toscana.core.transformation.logging.Log) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) File(java.io.File) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) Before(org.junit.Before)

Example 10 with CsarImpl

use of org.opentosca.toscana.core.csar.CsarImpl in project TOSCAna by StuPro-TOSCAna.

the class TransformationFilesystemDaoTest method setUp.

@Before
public void setUp() throws InvalidCsarException {
    csar = spy(new CsarImpl(new File(""), "csar1", logMock()));
    doReturn(new File("")).when(csar).getTemplate();
    EffectiveModelFactory modelFactory = mock(EffectiveModelFactory.class);
    EffectiveModel model = modelMock();
    when(modelFactory.create(any(File.class), any(Log.class))).thenReturn(model);
    transformationDao = new TransformationFilesystemDao(platformService, modelFactory);
    transformationDao.setCsarDao(csarDao);
    transformation = new TransformationImpl(csar, PLATFORM1, logMock(), modelMock());
    transformationRootDir = transformationDao.getRootDir(transformation);
}
Also used : Log(org.opentosca.toscana.core.transformation.logging.Log) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) File(java.io.File) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) Before(org.junit.Before)

Aggregations

CsarImpl (org.opentosca.toscana.core.csar.CsarImpl)11 File (java.io.File)8 Csar (org.opentosca.toscana.core.csar.Csar)8 Before (org.junit.Before)6 TransformationImpl (org.opentosca.toscana.core.transformation.TransformationImpl)5 Transformation (org.opentosca.toscana.core.transformation.Transformation)4 Platform (org.opentosca.toscana.core.transformation.platform.Platform)4 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)4 HashSet (java.util.HashSet)3 TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)3 Log (org.opentosca.toscana.core.transformation.logging.Log)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)2 CsarService (org.opentosca.toscana.core.csar.CsarService)2 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1