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));
}
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);
}
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();
}
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);
}
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);
}
Aggregations