Search in sources :

Example 1 with Preferences

use of org.opentosca.toscana.core.util.Preferences in project TOSCAna by StuPro-TOSCAna.

the class MapperTest method init.

public static BaseImageMapper init() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    InputStream in = BaseImageMapper.class.getClassLoader().getResourceAsStream("kubernetes/base-image-mapper/image-map.json");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copy(in, out);
    Preferences preferences = mock(Preferences.class);
    when(preferences.getDataDir()).thenReturn(staticTmpDir);
    TagStorage tagStorage = new TagStorage(preferences);
    BaseImageMapper baseImageMapper = new BaseImageMapper(new DockerBaseImages[] { ALPINE, DEBIAN, UBUNTU }, tagStorage);
    DataContainer data = mapper.readValue(new String(out.toByteArray()), DataContainer.class);
    baseImageMapper.setImageMap(data.data);
    return baseImageMapper;
}
Also used : DataContainer(org.opentosca.toscana.plugins.kubernetes.docker.mapper.util.DataContainer) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Preferences(org.opentosca.toscana.core.util.Preferences) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with Preferences

use of org.opentosca.toscana.core.util.Preferences 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)

Aggregations

InputStream (java.io.InputStream)2 Preferences (org.opentosca.toscana.core.util.Preferences)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotEquals (org.junit.Assert.assertNotEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mock (org.mockito.Mock)1 Mockito.when (org.mockito.Mockito.when)1 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)1 TestCsars (org.opentosca.toscana.core.testdata.TestCsars)1