Skip to content
Snippets Groups Projects
Unverified Commit 55832fe5 authored by Martin Weise's avatar Martin Weise
Browse files

Use different approach

parent b572d1c4
No related branches found
No related tags found
1 merge request!106Dev
...@@ -86,104 +86,55 @@ public abstract class BaseUnitTest { ...@@ -86,104 +86,55 @@ public abstract class BaseUnitTest {
.roles(List.of()) .roles(List.of())
.build(); .build();
public final static Long IMAGE_1_ID = 1L; public final static Long IMAGE_2_ID = 2L;
public final static String IMAGE_1_REPOSITORY = "mariadb"; public final static String IMAGE_2_REPOSITORY = "mariadb";
public final static String IMAGE_1_TAG = "10.5"; public final static String IMAGE_2_TAG = "10.5";
public final static String IMAGE_1_HASH = "83b40f2726e5"; public final static String IMAGE_2_HASH = "83b40f2726e5";
public final static Integer IMAGE_1_PORT = 5432; public final static Integer IMAGE_2_PORT = 3306;
public final static String IMAGE_1_DIALECT = "org.hibernate.dialect.MariaDBDialect"; public final static String IMAGE_2_DIALECT = "org.hibernate.dialect.MariaDBDialect";
public final static String IMAGE_1_DRIVER = "org.mariadb.jdbc.Driver"; public final static String IMAGE_2_DRIVER = "org.mariadb.jdbc.Driver";
public final static String IMAGE_1_JDBC = "mariadb"; public final static String IMAGE_2_JDBC = "mariadb";
public final static Long IMAGE_1_SIZE = 12000L; public final static Long IMAGE_2_SIZE = 12000L;
public final static Instant IMAGE_1_BUILT = Instant.now().minus(40, HOURS); public final static Instant IMAGE_2_BUILT = Instant.now().minus(40, HOURS);
public final static List<ContainerImageEnvironmentItem> IMAGE_1_ENV = List.of(ContainerImageEnvironmentItem.builder()
.iid(IMAGE_1_ID) public final static List<ContainerImageEnvironmentItem> IMAGE_2_ENV = List.of(ContainerImageEnvironmentItem.builder()
.iid(IMAGE_2_ID)
.key("MARIADB_USER") .key("MARIADB_USER")
.value("mariadb") .value("mariadb")
.type(ContainerImageEnvironmentItemType.USERNAME) .type(ContainerImageEnvironmentItemType.USERNAME)
.build(), .build(),
ContainerImageEnvironmentItem.builder() ContainerImageEnvironmentItem.builder()
.iid(IMAGE_1_ID) .iid(IMAGE_2_ID)
.key("MARIADB_PASSWORD") .key("MARIADB_PASSWORD")
.value("mariadb") .value("mariadb")
.type(ContainerImageEnvironmentItemType.PASSWORD) .type(ContainerImageEnvironmentItemType.PASSWORD)
.build(), .build(),
ContainerImageEnvironmentItem.builder() ContainerImageEnvironmentItem.builder()
.iid(IMAGE_1_ID) .iid(IMAGE_2_ID)
.key("MARIADB_ROOT_PASSWORD") .key("MARIADB_ROOT_PASSWORD")
.value("mariadb") .value("mariadb")
.type(ContainerImageEnvironmentItemType.PRIVILEGED_PASSWORD) .type(ContainerImageEnvironmentItemType.PRIVILEGED_PASSWORD)
.build(), .build(),
ContainerImageEnvironmentItem.builder() ContainerImageEnvironmentItem.builder()
.iid(IMAGE_1_ID) .iid(IMAGE_2_ID)
.key("UZERNAME") .key("UZERNAME")
.value("root") .value("root")
.type(ContainerImageEnvironmentItemType.PRIVILEGED_USERNAME) .type(ContainerImageEnvironmentItemType.PRIVILEGED_USERNAME)
.build()); .build());
public final static List<ImageEnvItemDto> IMAGE_1_ENV_DTO = List.of(ImageEnvItemDto.builder() public final static List<ImageEnvItemDto> IMAGE_2_ENV_DTO = List.of(ImageEnvItemDto.builder()
.iid(IMAGE_1_ID) .iid(IMAGE_2_ID)
.key("MARIADB_USER") .key("MARIADB_USER")
.value("mariadb") .value("mariadb")
.type(ImageEnvItemTypeDto.USERNAME) .type(ImageEnvItemTypeDto.USERNAME)
.build(), .build(),
ImageEnvItemDto.builder() ImageEnvItemDto.builder()
.iid(IMAGE_1_ID) .iid(IMAGE_2_ID)
.key("MARIADB_PASSWORD") .key("MARIADB_PASSWORD")
.value("mariadb") .value("mariadb")
.type(ImageEnvItemTypeDto.PASSWORD) .type(ImageEnvItemTypeDto.PASSWORD)
.build()); .build());
public final static ContainerImage IMAGE_1 = ContainerImage.builder()
.id(IMAGE_1_ID)
.repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG)
.hash(IMAGE_1_HASH)
.jdbcMethod(IMAGE_1_JDBC)
.dialect(IMAGE_1_DIALECT)
.driverClass(IMAGE_1_DRIVER)
.compiled(IMAGE_1_BUILT)
.size(IMAGE_1_SIZE)
.environment(IMAGE_1_ENV)
.defaultPort(IMAGE_1_PORT)
.build();
public final static Long IMAGE_2_ID = 2L;
public final static String IMAGE_2_REPOSITORY = "mysql";
public final static String IMAGE_2_TAG = "8.0";
public final static String IMAGE_2_HASH = "83b40f2726e5";
public final static Integer IMAGE_2_PORT = 3306;
public final static String IMAGE_2_DIALECT = "org.hibernate.dialect.MysqlDBDialect";
public final static String IMAGE_2_DRIVER = "org.mysql.jdbc.Driver";
public final static String IMAGE_2_JDBC = "mysql";
public final static Long IMAGE_2_SIZE = 12000L;
public final static Instant IMAGE_2_BUILT = Instant.now().minus(38, HOURS);
public final static List<ContainerImageEnvironmentItem> IMAGE_2_ENV = List.of(ContainerImageEnvironmentItem.builder()
.iid(IMAGE_2_ID)
.key("MYSQL_USER")
.value("mariadb")
.type(ContainerImageEnvironmentItemType.USERNAME)
.build(),
ContainerImageEnvironmentItem.builder()
.iid(IMAGE_2_ID)
.key("MYSQL_PASSWORD")
.value("mariadb")
.type(ContainerImageEnvironmentItemType.PASSWORD)
.build(),
ContainerImageEnvironmentItem.builder()
.iid(IMAGE_2_ID)
.key("MYSQL_ROOT_PASSWORD")
.value("mariadb")
.type(ContainerImageEnvironmentItemType.PRIVILEGED_PASSWORD)
.build(),
ContainerImageEnvironmentItem.builder()
.iid(IMAGE_2_ID)
.key("UZERNAME")
.value("root")
.type(ContainerImageEnvironmentItemType.PRIVILEGED_USERNAME)
.build());
public final static ContainerImageEnvironmentItem[] IMAGE_2_ENV_ARR = IMAGE_2_ENV.toArray(new ContainerImageEnvironmentItem[0]);
public final static ContainerImage IMAGE_2 = ContainerImage.builder() public final static ContainerImage IMAGE_2 = ContainerImage.builder()
.id(IMAGE_2_ID) .id(IMAGE_2_ID)
.repository(IMAGE_2_REPOSITORY) .repository(IMAGE_2_REPOSITORY)
...@@ -210,7 +161,7 @@ public abstract class BaseUnitTest { ...@@ -210,7 +161,7 @@ public abstract class BaseUnitTest {
.id(CONTAINER_1_ID) .id(CONTAINER_1_ID)
.name(CONTAINER_1_NAME) .name(CONTAINER_1_NAME)
.internalName(CONTAINER_1_INTERNALNAME) .internalName(CONTAINER_1_INTERNALNAME)
.image(IMAGE_1) .image(IMAGE_2)
.hash(CONTAINER_1_HASH) .hash(CONTAINER_1_HASH)
.ipAddress(CONTAINER_1_IP) .ipAddress(CONTAINER_1_IP)
.created(CONTAINER_1_CREATED) .created(CONTAINER_1_CREATED)
...@@ -228,7 +179,7 @@ public abstract class BaseUnitTest { ...@@ -228,7 +179,7 @@ public abstract class BaseUnitTest {
.id(CONTAINER_2_ID) .id(CONTAINER_2_ID)
.name(CONTAINER_2_NAME) .name(CONTAINER_2_NAME)
.internalName(CONTAINER_2_INTERNALNAME) .internalName(CONTAINER_2_INTERNALNAME)
.image(IMAGE_1) .image(IMAGE_2)
.hash(CONTAINER_2_HASH) .hash(CONTAINER_2_HASH)
.ipAddress(CONTAINER_2_IP) .ipAddress(CONTAINER_2_IP)
.created(CONTAINER_2_CREATED) .created(CONTAINER_2_CREATED)
...@@ -246,7 +197,7 @@ public abstract class BaseUnitTest { ...@@ -246,7 +197,7 @@ public abstract class BaseUnitTest {
.id(CONTAINER_3_ID) .id(CONTAINER_3_ID)
.name(CONTAINER_3_NAME) .name(CONTAINER_3_NAME)
.internalName(CONTAINER_3_INTERNALNAME) .internalName(CONTAINER_3_INTERNALNAME)
.image(IMAGE_1) .image(IMAGE_2)
.hash(CONTAINER_3_HASH) .hash(CONTAINER_3_HASH)
.ipAddress(CONTAINER_3_IP) .ipAddress(CONTAINER_3_IP)
.created(CONTAINER_3_CREATED) .created(CONTAINER_3_CREATED)
......
...@@ -79,7 +79,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { ...@@ -79,7 +79,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
/* mock data */ /* mock data */
userRepository.save(USER_1); userRepository.save(USER_1);
imageRepository.save(IMAGE_1); imageRepository.save(IMAGE_2);
} }
@AfterEach @AfterEach
...@@ -114,8 +114,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { ...@@ -114,8 +114,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
throws DockerClientException, ImageNotFoundException, ContainerAlreadyExistsException, throws DockerClientException, ImageNotFoundException, ContainerAlreadyExistsException,
UserNotFoundException { UserNotFoundException {
final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder() final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder()
.repository(IMAGE_1_REPOSITORY) .repository(IMAGE_2_REPOSITORY)
.tag(IMAGE_1_TAG) .tag(IMAGE_2_TAG)
.name(CONTAINER_1_NAME) .name(CONTAINER_1_NAME)
.build(); .build();
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
......
...@@ -47,7 +47,7 @@ public class ContainerServiceUnitTest extends BaseUnitTest { ...@@ -47,7 +47,7 @@ public class ContainerServiceUnitTest extends BaseUnitTest {
public void beforeEach() { public void beforeEach() {
/* mock data */ /* mock data */
userRepository.save(USER_1); userRepository.save(USER_1);
imageRepository.save(IMAGE_1); imageRepository.save(IMAGE_2);
containerRepository.save(CONTAINER_1); containerRepository.save(CONTAINER_1);
} }
...@@ -55,8 +55,8 @@ public class ContainerServiceUnitTest extends BaseUnitTest { ...@@ -55,8 +55,8 @@ public class ContainerServiceUnitTest extends BaseUnitTest {
public void create_nameExists_fails() { public void create_nameExists_fails() {
final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder() final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder()
.name(CONTAINER_1_NAME) .name(CONTAINER_1_NAME)
.repository(IMAGE_1_REPOSITORY) .repository(IMAGE_2_REPOSITORY)
.tag(IMAGE_1_TAG) .tag(IMAGE_2_TAG)
.build(); .build();
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
......
...@@ -3,7 +3,6 @@ package at.tuwien.service; ...@@ -3,7 +3,6 @@ package at.tuwien.service;
import at.tuwien.BaseUnitTest; import at.tuwien.BaseUnitTest;
import at.tuwien.api.container.image.ImageCreateDto; import at.tuwien.api.container.image.ImageCreateDto;
import at.tuwien.config.ReadyConfig; import at.tuwien.config.ReadyConfig;
import at.tuwien.entities.container.image.ContainerImage;
import at.tuwien.exception.*; import at.tuwien.exception.*;
import at.tuwien.repository.jpa.ContainerRepository; import at.tuwien.repository.jpa.ContainerRepository;
import at.tuwien.repository.jpa.ImageRepository; import at.tuwien.repository.jpa.ImageRepository;
...@@ -49,7 +48,6 @@ public class ImageServiceIntegrationTest extends BaseUnitTest { ...@@ -49,7 +48,6 @@ public class ImageServiceIntegrationTest extends BaseUnitTest {
public void beforeEach() { public void beforeEach() {
userRepository.save(USER_1); userRepository.save(USER_1);
imageRepository.save(IMAGE_2); imageRepository.save(IMAGE_2);
imageRepository.save(IMAGE_1);
} }
@Test @Test
...@@ -62,7 +60,7 @@ public class ImageServiceIntegrationTest extends BaseUnitTest { ...@@ -62,7 +60,7 @@ public class ImageServiceIntegrationTest extends BaseUnitTest {
.driverClass(IMAGE_2_DRIVER) .driverClass(IMAGE_2_DRIVER)
.jdbcMethod(IMAGE_2_JDBC) .jdbcMethod(IMAGE_2_JDBC)
.defaultPort(IMAGE_2_PORT) .defaultPort(IMAGE_2_PORT)
.environment(IMAGE_1_ENV_DTO) .environment(IMAGE_2_ENV_DTO)
.build(); .build();
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
...@@ -84,11 +82,11 @@ public class ImageServiceIntegrationTest extends BaseUnitTest { ...@@ -84,11 +82,11 @@ public class ImageServiceIntegrationTest extends BaseUnitTest {
final ImageCreateDto request = ImageCreateDto.builder() final ImageCreateDto request = ImageCreateDto.builder()
.repository("s0m3th1ng_n0t3x1st1ng") .repository("s0m3th1ng_n0t3x1st1ng")
.tag("d3v_h3ll") .tag("d3v_h3ll")
.dialect(IMAGE_1_DIALECT) .dialect(IMAGE_2_DIALECT)
.driverClass(IMAGE_1_DRIVER) .driverClass(IMAGE_2_DRIVER)
.jdbcMethod(IMAGE_1_JDBC) .jdbcMethod(IMAGE_2_JDBC)
.defaultPort(IMAGE_1_PORT) .defaultPort(IMAGE_2_PORT)
.environment(IMAGE_1_ENV_DTO) .environment(IMAGE_2_ENV_DTO)
.build(); .build();
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
...@@ -101,13 +99,13 @@ public class ImageServiceIntegrationTest extends BaseUnitTest { ...@@ -101,13 +99,13 @@ public class ImageServiceIntegrationTest extends BaseUnitTest {
@Test @Test
public void create_duplicate_fails() { public void create_duplicate_fails() {
final ImageCreateDto request = ImageCreateDto.builder() final ImageCreateDto request = ImageCreateDto.builder()
.repository(IMAGE_1_REPOSITORY) .repository(IMAGE_2_REPOSITORY)
.tag(IMAGE_1_TAG) .tag(IMAGE_2_TAG)
.defaultPort(IMAGE_1_PORT) .defaultPort(IMAGE_2_PORT)
.driverClass(IMAGE_1_DRIVER) .driverClass(IMAGE_2_DRIVER)
.jdbcMethod(IMAGE_1_JDBC) .jdbcMethod(IMAGE_2_JDBC)
.dialect(IMAGE_1_DIALECT) .dialect(IMAGE_2_DIALECT)
.environment(IMAGE_1_ENV_DTO) .environment(IMAGE_2_ENV_DTO)
.build(); .build();
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
...@@ -121,18 +119,18 @@ public class ImageServiceIntegrationTest extends BaseUnitTest { ...@@ -121,18 +119,18 @@ public class ImageServiceIntegrationTest extends BaseUnitTest {
public void delete_hasNoContainer_succeeds() throws ImageNotFoundException, PersistenceException { public void delete_hasNoContainer_succeeds() throws ImageNotFoundException, PersistenceException {
/* test */ /* test */
imageService.delete(IMAGE_1_ID); imageService.delete(IMAGE_2_ID);
assertTrue(imageRepository.findById(IMAGE_1_ID).isEmpty()); assertTrue(imageRepository.findById(IMAGE_2_ID).isEmpty());
assertFalse(containerRepository.findById(CONTAINER_1_ID).isPresent()); /* container should NEVER be deletable in the metadata db */ assertFalse(containerRepository.findById(CONTAINER_1_ID).isPresent()); /* container should NEVER be deletable in the metadata db */
} }
@Test @Test
public void delete_noContainer_succeeds() throws ImageNotFoundException, PersistenceException { public void delete_noContainer_succeeds() throws ImageNotFoundException, PersistenceException {
imageRepository.save(IMAGE_1); imageRepository.save(IMAGE_2);
/* test */ /* test */
imageService.delete(IMAGE_1_ID); imageService.delete(IMAGE_2_ID);
assertTrue(imageRepository.findById(IMAGE_1_ID).isEmpty()); assertTrue(imageRepository.findById(IMAGE_2_ID).isEmpty());
} }
} }
...@@ -44,48 +44,48 @@ public class ImageServiceUnitTest extends BaseUnitTest { ...@@ -44,48 +44,48 @@ public class ImageServiceUnitTest extends BaseUnitTest {
/* mock */ /* mock */
when(imageRepository.findAll()) when(imageRepository.findAll())
.thenReturn(List.of(IMAGE_1)); .thenReturn(List.of(IMAGE_2));
/* test */ /* test */
final List<ContainerImage> response = imageService.getAll(); final List<ContainerImage> response = imageService.getAll();
assertEquals(1, response.size()); assertEquals(1, response.size());
assertEquals(IMAGE_1_REPOSITORY, response.get(0).getRepository()); assertEquals(IMAGE_2_REPOSITORY, response.get(0).getRepository());
assertEquals(IMAGE_1_TAG, response.get(0).getTag()); assertEquals(IMAGE_2_TAG, response.get(0).getTag());
} }
@Test @Test
public void getById_succeeds() throws ImageNotFoundException { public void getById_succeeds() throws ImageNotFoundException {
/* mock */ /* mock */
when(imageRepository.findById(IMAGE_1_ID)) when(imageRepository.findById(IMAGE_2_ID))
.thenReturn(Optional.of(IMAGE_1)); .thenReturn(Optional.of(IMAGE_2));
/* test */ /* test */
final ContainerImage response = imageService.find(IMAGE_1_ID); final ContainerImage response = imageService.find(IMAGE_2_ID);
assertEquals(IMAGE_1_REPOSITORY, response.getRepository()); assertEquals(IMAGE_2_REPOSITORY, response.getRepository());
assertEquals(IMAGE_1_TAG, response.getTag()); assertEquals(IMAGE_2_TAG, response.getTag());
} }
@Test @Test
public void getById_notFound_fails() { public void getById_notFound_fails() {
/* mock */ /* mock */
when(imageRepository.findById(IMAGE_1_ID)) when(imageRepository.findById(IMAGE_2_ID))
.thenReturn(Optional.empty()); .thenReturn(Optional.empty());
/* test */ /* test */
assertThrows(ImageNotFoundException.class, () -> { assertThrows(ImageNotFoundException.class, () -> {
imageService.find(IMAGE_1_ID); imageService.find(IMAGE_2_ID);
}); });
} }
@Test @Test
public void create_duplicate_fails() { public void create_duplicate_fails() {
final ImageCreateDto request = ImageCreateDto.builder() final ImageCreateDto request = ImageCreateDto.builder()
.repository(IMAGE_1_REPOSITORY) .repository(IMAGE_2_REPOSITORY)
.tag(IMAGE_1_TAG) .tag(IMAGE_2_TAG)
.defaultPort(IMAGE_1_PORT) .defaultPort(IMAGE_2_PORT)
.environment(IMAGE_1_ENV_DTO) .environment(IMAGE_2_ENV_DTO)
.build(); .build();
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
...@@ -102,55 +102,55 @@ public class ImageServiceUnitTest extends BaseUnitTest { ...@@ -102,55 +102,55 @@ public class ImageServiceUnitTest extends BaseUnitTest {
@Test @Test
public void update_succeeds() throws ImageNotFoundException, DockerClientException { public void update_succeeds() throws ImageNotFoundException, DockerClientException {
final ImageChangeDto request = ImageChangeDto.builder() final ImageChangeDto request = ImageChangeDto.builder()
.environment(IMAGE_1_ENV_DTO) .environment(IMAGE_2_ENV_DTO)
.defaultPort(IMAGE_1_PORT) .defaultPort(IMAGE_2_PORT)
.build(); .build();
/* mock */ /* mock */
when(imageRepository.findById(IMAGE_1_ID)) when(imageRepository.findById(IMAGE_2_ID))
.thenReturn(Optional.of(IMAGE_1)); .thenReturn(Optional.of(IMAGE_2));
when(imageRepository.save(any())) when(imageRepository.save(any()))
.thenReturn(IMAGE_1); .thenReturn(IMAGE_2);
/* test */ /* test */
final ContainerImage response = imageService.update(IMAGE_1_ID, request); final ContainerImage response = imageService.update(IMAGE_2_ID, request);
assertEquals(IMAGE_1_REPOSITORY, response.getRepository()); assertEquals(IMAGE_2_REPOSITORY, response.getRepository());
assertEquals(IMAGE_1_TAG, response.getTag()); assertEquals(IMAGE_2_TAG, response.getTag());
} }
@Test @Test
public void update_port_succeeds() throws ImageNotFoundException, DockerClientException { public void update_port_succeeds() throws ImageNotFoundException, DockerClientException {
final ImageChangeDto request = ImageChangeDto.builder() final ImageChangeDto request = ImageChangeDto.builder()
.environment(IMAGE_1_ENV_DTO) .environment(IMAGE_2_ENV_DTO)
.defaultPort(9999) .defaultPort(9999)
.build(); .build();
/* mock */ /* mock */
when(imageRepository.findById(IMAGE_1_ID)) when(imageRepository.findById(IMAGE_2_ID))
.thenReturn(Optional.of(IMAGE_1)); .thenReturn(Optional.of(IMAGE_2));
when(imageRepository.save(any())) when(imageRepository.save(any()))
.thenReturn(IMAGE_1); .thenReturn(IMAGE_2);
/* test */ /* test */
final ContainerImage response = imageService.update(IMAGE_1_ID, request); final ContainerImage response = imageService.update(IMAGE_2_ID, request);
assertEquals(IMAGE_1_REPOSITORY, response.getRepository()); assertEquals(IMAGE_2_REPOSITORY, response.getRepository());
assertEquals(IMAGE_1_TAG, response.getTag()); assertEquals(IMAGE_2_TAG, response.getTag());
} }
@Test @Test
public void update_notFound_fails() { public void update_notFound_fails() {
final ImageChangeDto request = ImageChangeDto.builder() final ImageChangeDto request = ImageChangeDto.builder()
.environment(IMAGE_1_ENV_DTO) .environment(IMAGE_2_ENV_DTO)
.defaultPort(IMAGE_1_PORT) .defaultPort(IMAGE_2_PORT)
.build(); .build();
/* mock */ /* mock */
when(imageRepository.findById(IMAGE_1_ID)) when(imageRepository.findById(IMAGE_2_ID))
.thenReturn(Optional.empty()); .thenReturn(Optional.empty());
/* test */ /* test */
assertThrows(ImageNotFoundException.class, () -> { assertThrows(ImageNotFoundException.class, () -> {
imageService.update(IMAGE_1_ID, request); imageService.update(IMAGE_2_ID, request);
}); });
} }
...@@ -160,10 +160,10 @@ public class ImageServiceUnitTest extends BaseUnitTest { ...@@ -160,10 +160,10 @@ public class ImageServiceUnitTest extends BaseUnitTest {
/* mock */ /* mock */
doNothing() doNothing()
.when(imageRepository) .when(imageRepository)
.deleteById(IMAGE_1_ID); .deleteById(IMAGE_2_ID);
/* test */ /* test */
imageService.delete(IMAGE_1_ID); imageService.delete(IMAGE_2_ID);
} }
@Test @Test
...@@ -172,11 +172,11 @@ public class ImageServiceUnitTest extends BaseUnitTest { ...@@ -172,11 +172,11 @@ public class ImageServiceUnitTest extends BaseUnitTest {
/* mock */ /* mock */
doThrow(EntityNotFoundException.class) doThrow(EntityNotFoundException.class)
.when(imageRepository) .when(imageRepository)
.deleteById(IMAGE_1_ID); .deleteById(IMAGE_2_ID);
/* test */ /* test */
assertThrows(ImageNotFoundException.class, () -> { assertThrows(ImageNotFoundException.class, () -> {
imageService.delete(IMAGE_1_ID); imageService.delete(IMAGE_2_ID);
}); });
} }
...@@ -184,7 +184,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { ...@@ -184,7 +184,7 @@ public class ImageServiceUnitTest extends BaseUnitTest {
public void toString_omitSecrets_succeeds() { public void toString_omitSecrets_succeeds() {
/* test */ /* test */
final String response = IMAGE_1.toString(); final String response = IMAGE_2.toString();
assertFalse(response.contains("MARIADB_PASSWORD")); assertFalse(response.contains("MARIADB_PASSWORD"));
assertFalse(response.contains("MARIADB_ROOT_PASSWORD")); assertFalse(response.contains("MARIADB_ROOT_PASSWORD"));
} }
......
...@@ -80,7 +80,7 @@ public class Old extends BaseUnitTest { ...@@ -80,7 +80,7 @@ public class Old extends BaseUnitTest {
/* mock data */ /* mock data */
userRepository.save(USER_1); userRepository.save(USER_1);
imageRepository.save(IMAGE_1); imageRepository.save(IMAGE_2);
} }
@AfterEach @AfterEach
...@@ -111,302 +111,302 @@ public class Old extends BaseUnitTest { ...@@ -111,302 +111,302 @@ public class Old extends BaseUnitTest {
} }
public void create_succeeds() // public void create_succeeds()
throws DockerClientException, ImageNotFoundException, ContainerAlreadyExistsException, // throws DockerClientException, ImageNotFoundException, ContainerAlreadyExistsException,
UserNotFoundException { // UserNotFoundException {
final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder() // final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder()
.repository(IMAGE_1_REPOSITORY) // .repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG) // .tag(IMAGE_1_TAG)
.name(CONTAINER_1_NAME) // .name(CONTAINER_1_NAME)
.build(); // .build();
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); // final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
//
/* mock */ // /* mock */
when(containerRepository.findByInternalName(CONTAINER_1_INTERNALNAME)) // when(containerRepository.findByInternalName(CONTAINER_1_INTERNALNAME))
.thenReturn(Optional.empty()); // .thenReturn(Optional.empty());
when(containerRepository.save(any(Container.class))) // when(containerRepository.save(any(Container.class)))
.thenReturn(CONTAINER_1); // .thenReturn(CONTAINER_1);
//
/* test */ // /* test */
final Container container = containerService.create(request, principal); // final Container container = containerService.create(request, principal);
assertEquals(CONTAINER_1_NAME, container.getName()); // assertEquals(CONTAINER_1_NAME, container.getName());
assertEquals(1, userRepository.findAll().size()); // assertEquals(1, userRepository.findAll().size());
} // }
//
//
public void create_conflictingNames_fails() { // public void create_conflictingNames_fails() {
final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder() // final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder()
.repository(IMAGE_1_REPOSITORY) // .repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG) // .tag(IMAGE_1_TAG)
.name(CONTAINER_1_NAME) // .name(CONTAINER_1_NAME)
.build(); // .build();
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); // final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
//
/* mock */ // /* mock */
when(containerRepository.findByInternalName(CONTAINER_1_INTERNALNAME)) // when(containerRepository.findByInternalName(CONTAINER_1_INTERNALNAME))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
//
/* test */ // /* test */
assertThrows(ContainerAlreadyExistsException.class, () -> { // assertThrows(ContainerAlreadyExistsException.class, () -> {
containerService.create(request, principal); // containerService.create(request, principal);
}); // });
} // }
//
//
public void remove_alreadyRemoved_fails() { // public void remove_alreadyRemoved_fails() {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.empty()); // .thenReturn(Optional.empty());
//
/* test */ // /* test */
assertThrows(ContainerNotFoundException.class, () -> { // assertThrows(ContainerNotFoundException.class, () -> {
containerService.remove(CONTAINER_1_ID); // containerService.remove(CONTAINER_1_ID);
}); // });
} // }
//
//
public void create_notFound_fails() { // public void create_notFound_fails() {
final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder() // final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder()
.repository(IMAGE_2_REPOSITORY) // .repository(IMAGE_2_REPOSITORY)
.tag(IMAGE_2_TAG) // .tag(IMAGE_2_TAG)
.name(CONTAINER_3_NAME) // .name(CONTAINER_3_NAME)
.build(); // .build();
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); // final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
//
/* mock */ // /* mock */
//
/* test */ // /* test */
assertThrows(ImageNotFoundException.class, () -> { // assertThrows(ImageNotFoundException.class, () -> {
containerService.create(request, principal); // containerService.create(request, principal);
}); // });
} // }
//
//
//
public void findById_notFound_fails() { // public void findById_notFound_fails() {
//
/* mock */ // /* mock */
//
/* test */ // /* test */
assertThrows(ContainerNotFoundException.class, () -> { // assertThrows(ContainerNotFoundException.class, () -> {
containerService.find(CONTAINER_1_ID); // containerService.find(CONTAINER_1_ID);
}); // });
} // }
//
//
public void change_start_succeeds() throws DockerClientException, ContainerNotFoundException { // public void change_start_succeeds() throws DockerClientException, ContainerNotFoundException {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
dockerUtil.createContainer(CONTAINER_1); // dockerUtil.createContainer(CONTAINER_1);
//
/* test */ // /* test */
containerService.start(CONTAINER_1_ID); // containerService.start(CONTAINER_1_ID);
} // }
//
//
public void change_stop_succeeds() throws DockerClientException, InterruptedException, ContainerNotFoundException { // public void change_stop_succeeds() throws DockerClientException, InterruptedException, ContainerNotFoundException {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
dockerUtil.createContainer(CONTAINER_1); // dockerUtil.createContainer(CONTAINER_1);
dockerUtil.startContainer(CONTAINER_1); // dockerUtil.startContainer(CONTAINER_1);
//
/* test */ // /* test */
containerService.stop(CONTAINER_1_ID); // containerService.stop(CONTAINER_1_ID);
} // }
//
//
public void change_startSavedButNotFound_fails() { // public void change_startSavedButNotFound_fails() {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
//
/* test */ // /* test */
assertThrows(DockerClientException.class, () -> { // assertThrows(DockerClientException.class, () -> {
containerService.start(CONTAINER_1_ID); // containerService.start(CONTAINER_1_ID);
}); // });
} // }
//
//
public void change_removeSavedButNotFound_fails() { // public void change_removeSavedButNotFound_fails() {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
//
/* test */ // /* test */
assertThrows(DockerClientException.class, () -> { // assertThrows(DockerClientException.class, () -> {
containerService.remove(CONTAINER_1_ID); // containerService.remove(CONTAINER_1_ID);
}); // });
} // }
//
//
public void getAll_succeeds() { // public void getAll_succeeds() {
//
/* mock */ // /* mock */
when(containerRepository.findAll()) // when(containerRepository.findAll())
.thenReturn(List.of(CONTAINER_1, CONTAINER_2)); // .thenReturn(List.of(CONTAINER_1, CONTAINER_2));
//
/* test */ // /* test */
final List<Container> response = containerService.getAll(); // final List<Container> response = containerService.getAll();
assertEquals(2, response.size()); // assertEquals(2, response.size());
} // }
//
//
public void remove_succeeds() throws DockerClientException, ContainerStillRunningException, ContainerNotFoundException { // public void remove_succeeds() throws DockerClientException, ContainerStillRunningException, ContainerNotFoundException {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
dockerUtil.createContainer(CONTAINER_1); // dockerUtil.createContainer(CONTAINER_1);
dockerUtil.stopContainer(CONTAINER_1); // dockerUtil.stopContainer(CONTAINER_1);
//
/* test */ // /* test */
containerService.remove(CONTAINER_1_ID); // containerService.remove(CONTAINER_1_ID);
} // }
//
//
public void remove_notFound_fails() { // public void remove_notFound_fails() {
//
/* test */ // /* test */
assertThrows(ContainerNotFoundException.class, () -> { // assertThrows(ContainerNotFoundException.class, () -> {
containerService.remove(CONTAINER_1_ID); // containerService.remove(CONTAINER_1_ID);
}); // });
} // }
//
//
public void remove_stillRunning_fails() throws InterruptedException { // public void remove_stillRunning_fails() throws InterruptedException {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
dockerUtil.createContainer(CONTAINER_1); // dockerUtil.createContainer(CONTAINER_1);
dockerUtil.startContainer(CONTAINER_1); // dockerUtil.startContainer(CONTAINER_1);
//
/* test */ // /* test */
assertThrows(ContainerStillRunningException.class, () -> { // assertThrows(ContainerStillRunningException.class, () -> {
containerService.remove(CONTAINER_1_ID); // containerService.remove(CONTAINER_1_ID);
}); // });
} // }
//
//
public void change_alreadyRunning_fails() throws InterruptedException { // public void change_alreadyRunning_fails() throws InterruptedException {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
dockerUtil.createContainer(CONTAINER_1); // dockerUtil.createContainer(CONTAINER_1);
dockerUtil.startContainer(CONTAINER_1); // dockerUtil.startContainer(CONTAINER_1);
//
/* test */ // /* test */
assertThrows(DockerClientException.class, () -> { // assertThrows(DockerClientException.class, () -> {
containerService.start(CONTAINER_1_ID); // containerService.start(CONTAINER_1_ID);
}); // });
} // }
//
//
public void change_startNotFound_fails() { // public void change_startNotFound_fails() {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.empty()); // .thenReturn(Optional.empty());
dockerUtil.createContainer(CONTAINER_1); // dockerUtil.createContainer(CONTAINER_1);
//
/* test */ // /* test */
assertThrows(ContainerNotFoundException.class, () -> { // assertThrows(ContainerNotFoundException.class, () -> {
containerService.start(CONTAINER_1_ID); // containerService.start(CONTAINER_1_ID);
}); // });
} // }
//
//
public void change_alreadyStopped_fails() throws InterruptedException { // public void change_alreadyStopped_fails() throws InterruptedException {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
dockerUtil.createContainer(CONTAINER_1); // dockerUtil.createContainer(CONTAINER_1);
dockerUtil.startContainer(CONTAINER_1); // dockerUtil.startContainer(CONTAINER_1);
dockerUtil.stopContainer(CONTAINER_1); // dockerUtil.stopContainer(CONTAINER_1);
//
/* test */ // /* test */
assertThrows(DockerClientException.class, () -> { // assertThrows(DockerClientException.class, () -> {
containerService.stop(CONTAINER_1_ID); // containerService.stop(CONTAINER_1_ID);
}); // });
} // }
//
//
public void change_stopNeverStarted_fails() { // public void change_stopNeverStarted_fails() {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
dockerUtil.createContainer(CONTAINER_1); // dockerUtil.createContainer(CONTAINER_1);
//
/* test */ // /* test */
assertThrows(DockerClientException.class, () -> { // assertThrows(DockerClientException.class, () -> {
containerService.stop(CONTAINER_1_ID); // containerService.stop(CONTAINER_1_ID);
}); // });
} // }
//
//
public void change_stopSavedButNotFound_fails() { // public void change_stopSavedButNotFound_fails() {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
//
/* test */ // /* test */
assertThrows(DockerClientException.class, () -> { // assertThrows(DockerClientException.class, () -> {
containerService.stop(CONTAINER_1_ID); // containerService.stop(CONTAINER_1_ID);
}); // });
} // }
//
//
public void inspect_succeeds() throws InterruptedException, DockerClientException, ContainerNotFoundException, // public void inspect_succeeds() throws InterruptedException, DockerClientException, ContainerNotFoundException,
ContainerNotRunningException { // ContainerNotRunningException {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
dockerUtil.createContainer(CONTAINER_1); // dockerUtil.createContainer(CONTAINER_1);
dockerUtil.startContainer(CONTAINER_1); // dockerUtil.startContainer(CONTAINER_1);
//
/* test */ // /* test */
final Container response = containerService.inspect(CONTAINER_1_ID); // final Container response = containerService.inspect(CONTAINER_1_ID);
assertEquals(CONTAINER_1_ID, response.getId()); // assertEquals(CONTAINER_1_ID, response.getId());
assertEquals(CONTAINER_1_NAME, response.getName()); // assertEquals(CONTAINER_1_NAME, response.getName());
assertEquals(CONTAINER_1_INTERNALNAME, response.getInternalName()); // assertEquals(CONTAINER_1_INTERNALNAME, response.getInternalName());
assertEquals(CONTAINER_1_IP, response.getIpAddress()); // assertEquals(CONTAINER_1_IP, response.getIpAddress());
} // }
//
//
public void inspect_notFound_fails() { // public void inspect_notFound_fails() {
//
/* mock */ // /* mock */
//
/* test */ // /* test */
assertThrows(ContainerNotFoundException.class, () -> { // assertThrows(ContainerNotFoundException.class, () -> {
containerService.inspect(CONTAINER_2_ID); // containerService.inspect(CONTAINER_2_ID);
}); // });
} // }
//
//
public void inspect_notRunning_fails() { // public void inspect_notRunning_fails() {
//
/* mock */ // /* mock */
when(containerRepository.findById(CONTAINER_1_ID)) // when(containerRepository.findById(CONTAINER_1_ID))
.thenReturn(Optional.of(CONTAINER_1)); // .thenReturn(Optional.of(CONTAINER_1));
dockerUtil.createContainer(CONTAINER_1); // dockerUtil.createContainer(CONTAINER_1);
//
/* test */ // /* test */
assertThrows(ContainerNotRunningException.class, () -> { // assertThrows(ContainerNotRunningException.class, () -> {
containerService.inspect(CONTAINER_1_ID); // containerService.inspect(CONTAINER_1_ID);
}); // });
} // }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment