feature/add-i18n-support (#167)
Co-authored-by: Michael Hoennig <michael@hoennig.de> Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/167 Reviewed-by: Marc Sandlus <marc.sandlus@hostsharing.net>
This commit is contained in:
+5
-3
@@ -18,9 +18,11 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.get;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
|
||||
import static java.util.Map.entry;
|
||||
import static net.hostsharing.hsadminng.config.HttpHeadersBuilder.headers;
|
||||
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -69,13 +71,13 @@ class CasAuthenticationFilterIntegrationTest {
|
||||
final var result = restTemplate.exchange(
|
||||
"http://localhost:" + this.serverPort + "/api/ping",
|
||||
HttpMethod.GET,
|
||||
new HttpEntity<>(null, headers("Authorization", "ST-valid")),
|
||||
new HttpEntity<>(null, headers(entry("Authorization", "ST-valid"))),
|
||||
String.class
|
||||
);
|
||||
|
||||
// then
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("pong " + username + "\n");
|
||||
assertThat(result.getBody()).startsWith("pong " + username);
|
||||
// HOWTO assert log messages
|
||||
assertThat(capturedOutput.getOut()).containsPattern(
|
||||
LogbackLogPattern.of(LogLevel.DEBUG, RealCasAuthenticator.class, "CAS-user: " + username));
|
||||
@@ -97,7 +99,7 @@ class CasAuthenticationFilterIntegrationTest {
|
||||
final var result = restTemplate.exchange(
|
||||
"http://localhost:" + this.serverPort + "/api/ping",
|
||||
HttpMethod.GET,
|
||||
new HttpEntity<>(null, headers("Authorization", "invalid")),
|
||||
new HttpEntity<>(null, headers(entry("Authorization", "invalid"))),
|
||||
String.class
|
||||
);
|
||||
|
||||
|
||||
@@ -2,11 +2,16 @@ package net.hostsharing.hsadminng.config;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class HttpHeadersBuilder {
|
||||
|
||||
public static HttpHeaders headers(final String key, final String value) {
|
||||
final var headers = new HttpHeaders();
|
||||
headers.set(key, value);
|
||||
return headers;
|
||||
@SafeVarargs
|
||||
public static HttpHeaders headers(final Map.Entry<String, String>... headers) {
|
||||
final var httpHeaders = new HttpHeaders();
|
||||
for (Map.Entry<String, String> entry : headers) {
|
||||
httpHeaders.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return httpHeaders;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-27
@@ -1,5 +1,6 @@
|
||||
package net.hostsharing.hsadminng.errors;
|
||||
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -20,6 +21,7 @@ import jakarta.persistence.EntityNotFoundException;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -27,7 +29,8 @@ import static org.mockito.Mockito.when;
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RestResponseEntityExceptionHandlerUnitTest {
|
||||
|
||||
final RestResponseEntityExceptionHandler exceptionHandler = new RestResponseEntityExceptionHandler();
|
||||
final RestResponseEntityExceptionHandler exceptionHandler =
|
||||
new RestResponseEntityExceptionHandler(mock(MessageTranslator.class), emptyList());
|
||||
|
||||
@Test
|
||||
void handleConflict() {
|
||||
@@ -46,20 +49,16 @@ class RestResponseEntityExceptionHandlerUnitTest {
|
||||
@Test
|
||||
void handleForeignKeyViolation() {
|
||||
// given
|
||||
final var givenException = new DataIntegrityViolationException("""
|
||||
... violates foreign key constraint ...
|
||||
Detail: Second Line
|
||||
Third Line
|
||||
""");
|
||||
final var givenException = new DataIntegrityViolationException("... violates foreign key constraint ...");
|
||||
final var givenWebRequest = mock(WebRequest.class);
|
||||
|
||||
// when
|
||||
final var errorResponse = exceptionHandler.handleConflict(givenException, givenWebRequest);
|
||||
|
||||
// then
|
||||
assertThat(errorResponse.getBody().getStatusCode()).isEqualTo(400);
|
||||
assertThat(errorResponse.getBody()).isNotNull()
|
||||
.extracting(CustomErrorResponse::getMessage).isEqualTo("ERROR: [400] Second Line");
|
||||
assertThat(errorResponse.getBody().getStatusCode()).isEqualTo(HttpStatus.CONFLICT.value());
|
||||
assertThat(errorResponse.getBody()).isNotNull().extracting(CustomErrorResponse::getMessage).isEqualTo(
|
||||
"ERROR: [409] ... violates foreign key constraint ...");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,24 +126,6 @@ class RestResponseEntityExceptionHandlerUnitTest {
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("ERROR: [400] whatever error message");
|
||||
}
|
||||
|
||||
@Test
|
||||
void handleJpaObjectRetrievalFailureExceptionWithEntityName() {
|
||||
// given
|
||||
final var givenException = new JpaObjectRetrievalFailureException(
|
||||
new EntityNotFoundException("Unable to find "
|
||||
+ NoDisplayNameEntity.class.getTypeName()
|
||||
+ " with id 12345-123454")
|
||||
);
|
||||
final var givenWebRequest = mock(WebRequest.class);
|
||||
|
||||
// when
|
||||
final var errorResponse = exceptionHandler.handleJpaObjectRetrievalFailureException(givenException, givenWebRequest);
|
||||
|
||||
// then
|
||||
assertThat(errorResponse.getBody().getStatusCode()).isEqualTo(400);
|
||||
assertThat(errorResponse.getBody().getMessage()).isEqualTo("ERROR: [400] Unable to find NoDisplayNameEntity with uuid 12345-123454");
|
||||
}
|
||||
|
||||
@Test
|
||||
void jpaExceptionWithUnknownErrorCode() {
|
||||
// given
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ import static org.hamcrest.Matchers.matchesRegex;
|
||||
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class}
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package net.hostsharing.hsadminng.hs.booking.item;
|
||||
|
||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.booking.generated.api.v1.model.HsBookingItemInsertResource;
|
||||
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity;
|
||||
@@ -42,7 +43,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsBookingItemController.class)
|
||||
@Import({StrictMapper.class, JsonObjectMapperConfiguration.class, DisableSecurityConfig.class})
|
||||
@Import({StrictMapper.class, JsonObjectMapperConfiguration.class, DisableSecurityConfig.class, MessageTranslator.class})
|
||||
@RunWith(SpringRunner.class)
|
||||
@ActiveProfiles("test")
|
||||
class HsBookingItemControllerRestTest {
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import lombok.SneakyThrows;
|
||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRealRepository;
|
||||
import net.hostsharing.hsadminng.mapper.Array;
|
||||
@@ -55,7 +56,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsHostingAssetController.class)
|
||||
@Import({ StrictMapper.class, JsonObjectMapperConfiguration.class, DisableSecurityConfig.class })
|
||||
@Import({ StrictMapper.class, JsonObjectMapperConfiguration.class, DisableSecurityConfig.class, MessageTranslator.class })
|
||||
@RunWith(SpringRunner.class)
|
||||
@ActiveProfiles("test")
|
||||
public class HsHostingAssetControllerRestTest {
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ class HsCloudServerHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'identifier' expected to match '^vm[0-9][0-9][0-9][0-9]$', but is 'xyz99'");
|
||||
"'identifier' expected to match '^vm[0-9][0-9][0-9][0-9]$' but is 'xyz99'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -121,7 +121,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^\\Qexample.org|DNS\\E$', but is 'example.org'"
|
||||
"'identifier' expected to match '^\\Qexample.org|DNS\\E$' but is 'example.org'"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'DOMAIN_DNS_SETUP:example.org|DNS.config.TTL' is expected to be of type Integer, but is of type String",
|
||||
"'DOMAIN_DNS_SETUP:example.org|DNS.config.TTL' is expected to be of type Integer but is of type String",
|
||||
"'DOMAIN_DNS_SETUP:example.org|DNS.config.user-RR' is expected to match any of [(\\*\\.)?([a-zA-Z0-9\\._-]+|@)[ \t]+(([1-9][0-9]*[mMhHdDwW]?)+[ \t]+)?[iI][nN][ \t]+[a-zA-Z]+[ \t]+(([^;]+)|(\".*\")|(\\(.*\\)))[ \t]*(;.*)?, (\\*\\.)?([a-zA-Z0-9\\._-]+|@)[ \t]+[iI][nN][ \t]+(([1-9][0-9]*[mMhHdDwW]?)+[ \t]+)?[a-zA-Z]+[ \t]+(([^;]+)|(\".*\")|(\\(.*\\)))[ \t]*(;.*)?] but '@ 1814400 IN 1814400 BAD1 TTL only allowed once' does not match any",
|
||||
"'DOMAIN_DNS_SETUP:example.org|DNS.config.user-RR' is expected to match any of [(\\*\\.)?([a-zA-Z0-9\\._-]+|@)[ \t]+(([1-9][0-9]*[mMhHdDwW]?)+[ \t]+)?[iI][nN][ \t]+[a-zA-Z]+[ \t]+(([^;]+)|(\".*\")|(\\(.*\\)))[ \t]*(;.*)?, (\\*\\.)?([a-zA-Z0-9\\._-]+|@)[ \t]+[iI][nN][ \t]+(([1-9][0-9]*[mMhHdDwW]?)+[ \t]+)?[a-zA-Z]+[ \t]+(([^;]+)|(\".*\")|(\\(.*\\)))[ \t]*(;.*)?] but 'www BAD1 Record-Class missing / not enough columns' does not match any");
|
||||
}
|
||||
|
||||
+2
-2
@@ -88,7 +88,7 @@ class HsDomainHttpSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^\\Qexample.org|HTTP\\E$', but is 'example.org'"
|
||||
"'identifier' expected to match '^\\Qexample.org|HTTP\\E$' but is 'example.org'"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ class HsDomainHttpSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.htdocsfallback' is expected to be of type Boolean, but is of type String",
|
||||
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.htdocsfallback' is expected to be of type Boolean but is of type String",
|
||||
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.fcgi-php-bin' is expected to match [^/.*] but 'false' does not match",
|
||||
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match [(\\*|(?!-)[A-Za-z0-9-]{1,63}(?<!-))] but '' does not match",
|
||||
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match [(\\*|(?!-)[A-Za-z0-9-]{1,63}(?<!-))] but '@' does not match",
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ class HsDomainMboxHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^\\Qexample.org|MBOX\\E$', but is 'example.org'"
|
||||
"'identifier' expected to match '^\\Qexample.org|MBOX\\E$' but is 'example.org'"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -93,7 +93,7 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).contains(
|
||||
"'identifier' expected to match '(\\*|(?!-)[A-Za-z0-9-]{1,63}(?<!-))\\.example\\.org', but is '"
|
||||
"'identifier' expected to match '(\\*|(?!-)[A-Za-z0-9-]{1,63}(?<!-))\\.example\\.org' but is '"
|
||||
+ testCase.domainName + "'"
|
||||
);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'identifier' expected to match 'example.org', but is 'not-matching-booking-item-domain-name.org'");
|
||||
"'identifier' expected to match 'example.org' but is 'not-matching-booking-item-domain-name.org'");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -197,8 +197,8 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'identifier' expected to match '(\\*|(?!-)[A-Za-z0-9-]{1,63}(?<!-))\\.example\\.org', " +
|
||||
"but is '" + newDomainName + "'");
|
||||
"'identifier' expected to match '(\\*|(?!-)[A-Za-z0-9-]{1,63}(?<!-))\\.example\\.org'" +
|
||||
" but is '" + newDomainName + "'");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -490,7 +490,7 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
void isRejectedDueToInvalidIdentifier() {
|
||||
assertThat(validate()).contains(
|
||||
"'identifier' expected to match '(\\*|(?!-)[A-Za-z0-9-]{1,63}(?<!-))\\.example\\.net', but is 'sub.example.org'"
|
||||
"'identifier' expected to match '(\\*|(?!-)[A-Za-z0-9-]{1,63}(?<!-))\\.example\\.net' but is 'sub.example.org'"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ class HsDomainSmtpSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^\\Qexample.org|SMTP\\E$', but is 'example.org'"
|
||||
"'identifier' expected to match '^\\Qexample.org|SMTP\\E$' but is 'example.org'"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -196,7 +196,7 @@ class HsEMailAddressHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'identifier' expected to match '^\\Qold-local-part@example.org\\E$', but is 'abc00-office'");
|
||||
"'identifier' expected to match '^\\Qold-local-part@example.org\\E$' but is 'abc00-office'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -119,7 +119,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'identifier' expected to match '^xyz00$|^xyz00-[a-z0-9][a-z0-9\\._-]*$', but is 'abc00-office'");
|
||||
"'identifier' expected to match '^xyz00$|^xyz00-[a-z0-9][a-z0-9\\._-]*$' but is 'abc00-office'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ class HsIPv4NumberHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}$', but is '" + givenIdentifier + "'"
|
||||
"'identifier' expected to match '^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}$' but is '" + givenIdentifier + "'"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ class HsIPv6NumberHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).contains(
|
||||
"'identifier' expected to be a valid IPv6 address, but is '" + givenIdentifier + "'"
|
||||
"'identifier' expected to be a valid IPv6 address but is '" + givenIdentifier + "'"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -43,7 +43,7 @@ class HsManagedServerHostingAssetValidatorUnitTest {
|
||||
"'MANAGED_SERVER:vm1234.assignedToAsset' must be null but is of type CLOUD_SERVER",
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_cpu_usage' is expected to be at least 10 but is 2",
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_ram_usage' is expected to be at most 100 but is 101",
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_hdd_usage' is expected to be of type Integer, but is of type String");
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_hdd_usage' is expected to be of type Integer but is of type String");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,7 +61,7 @@ class HsManagedServerHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'identifier' expected to match '^vm[0-9][0-9][0-9][0-9]$', but is 'xyz00'");
|
||||
"'identifier' expected to match '^vm[0-9][0-9][0-9][0-9]$' but is 'xyz00'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
|
||||
final var result = validator.validateEntity(mangedWebspaceHostingAssetEntity);
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly("'identifier' expected to match '^abc[0-9][0-9]$', but is 'xyz00'");
|
||||
assertThat(result).containsExactly("'identifier' expected to match '^abc[0-9][0-9]$' but is 'xyz00'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -100,7 +100,7 @@ class HsMariaDbDatabaseHostingAssetValidatorUnitTest {
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'MARIADB_DATABASE:MAD|xyz00_temp.config.unknown' is not expected but is set to 'wrong'",
|
||||
"'MARIADB_DATABASE:MAD|xyz00_temp.config.encoding' is expected to be of type String, but is of type Integer"
|
||||
"'MARIADB_DATABASE:MAD|xyz00_temp.config.encoding' is expected to be of type String but is of type Integer"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -117,6 +117,6 @@ class HsMariaDbDatabaseHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^MAD\\|xyz00$|^MAD\\|xyz00_[a-zA-Z0-9_]+$', but is 'xyz99-temp'");
|
||||
"'identifier' expected to match '^MAD\\|xyz00$|^MAD\\|xyz00_[a-zA-Z0-9_]+$' but is 'xyz99-temp'");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ class HsMariaDbInstanceHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^\\Qvm1234|MariaDB.default\\E$', but is 'example.org'"
|
||||
"'identifier' expected to match '^\\Qvm1234|MariaDB.default\\E$' but is 'example.org'"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -128,6 +128,6 @@ class HsMariaDbUserHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^MAU\\|xyz00$|^MAU\\|xyz00_[a-zA-Z0-9_]+$', but is 'xyz99-temp'");
|
||||
"'identifier' expected to match '^MAU\\|xyz00$|^MAU\\|xyz00_[a-zA-Z0-9_]+$' but is 'xyz99-temp'");
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -123,7 +123,7 @@ class HsPostgreSqlDatabaseHostingAssetValidatorUnitTest {
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'PGSQL_DATABASE:PGD|xyz00_db.config.unknown' is not expected but is set to 'wrong'",
|
||||
"'PGSQL_DATABASE:PGD|xyz00_db.config.encoding' is expected to be of type String, but is of type Integer"
|
||||
"'PGSQL_DATABASE:PGD|xyz00_db.config.encoding' is expected to be of type String but is of type Integer"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -140,6 +140,6 @@ class HsPostgreSqlDatabaseHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^PGD\\|xyz00$|^PGD\\|xyz00_[a-zA-Z0-9_]+$', but is 'xyz99-temp'");
|
||||
"'identifier' expected to match '^PGD\\|xyz00$|^PGD\\|xyz00_[a-zA-Z0-9_]+$' but is 'xyz99-temp'");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^\\Qvm1234|PgSql.default\\E$', but is 'PostgreSQL'"
|
||||
"'identifier' expected to match '^\\Qvm1234|PgSql.default\\E$' but is 'PostgreSQL'"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -126,6 +126,6 @@ class HsPostgreSqlUserHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^PGU\\|xyz00$|^PGU\\|xyz00_[a-zA-Z0-9_]+$', but is 'xyz99-temp'");
|
||||
"'identifier' expected to match '^PGU\\|xyz00$|^PGU\\|xyz00_[a-zA-Z0-9_]+$' but is 'xyz99-temp'");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ class HsUnixUserHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^abc00$|^abc00-[a-z0-9\\._-]+$', but is 'xyz99-temp'");
|
||||
"'identifier' expected to match '^abc00$|^abc00-[a-z0-9\\._-]+$' but is 'xyz99-temp'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1230,7 +1230,7 @@ public class ImportHostingAssets extends CsvDataImport {
|
||||
final var free = rec.getBoolean("free");
|
||||
|
||||
assertThat(old_inet_addr_id)
|
||||
.as("packet.old_inet_addr_id not supported, but is not null for " + packet_name)
|
||||
.as("packet.old_inet_addr_id not supported but is not null for " + packet_name)
|
||||
.isNull();
|
||||
|
||||
final var biType = determineBiType(basepacket_code);
|
||||
@@ -1245,7 +1245,7 @@ public class ImportHostingAssets extends CsvDataImport {
|
||||
|
||||
logError(() -> assertThat(!free || haType == MANAGED_WEBSPACE || defaultPrefix(bookingItem)
|
||||
.equals("hsh"))
|
||||
.as("packet.free only supported for Hostsharing-Assets and ManagedWebspace in customer-ManagedServer, but is set for "
|
||||
.as("packet.free only supported for Hostsharing-Assets and ManagedWebspace in customer-ManagedServerbut is set for "
|
||||
+ packet_name)
|
||||
.isTrue());
|
||||
|
||||
@@ -1739,7 +1739,7 @@ public class ImportHostingAssets extends CsvDataImport {
|
||||
return givenValue != null && !givenValue.isBlank() ? givenValue : defaultStringValue;
|
||||
}
|
||||
throw new RuntimeException(
|
||||
"property default value expected to be of type string, but is of type " + defaultValue.getClass()
|
||||
"property default value expected to be of type stringbut is of type " + defaultValue.getClass()
|
||||
.getSimpleName());
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class PostgresTestcontainer {
|
||||
}
|
||||
|
||||
private static void makeDir(final File dir) {
|
||||
assertThat(!dir.exists() || dir.isDirectory()).describedAs(dir + " does exist, but is not a directory").isTrue();
|
||||
assertThat(!dir.exists() || dir.isDirectory()).describedAs(dir + " does exist but is not a directory").isTrue();
|
||||
assertThat(dir.isDirectory() || dir.mkdirs()).describedAs(dir + " cannot be created").isTrue();
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.bankaccount;
|
||||
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
@@ -19,7 +20,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsOfficeBankAccountController.class)
|
||||
@Import(DisableSecurityConfig.class)
|
||||
@Import({DisableSecurityConfig.class, MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
class HsOfficeBankAccountControllerRestTest {
|
||||
|
||||
|
||||
+5
-2
@@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.hs.office.coopassets;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
@@ -34,7 +35,8 @@ import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class,
|
||||
MessageTranslator.class}
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
@@ -355,6 +357,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -376,7 +379,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
{
|
||||
"statusCode": 400,
|
||||
"statusPhrase": "Bad Request",
|
||||
"message": "ERROR: [400] coop assets transaction would result in a negative balance of assets"
|
||||
"message": "ERROR: [400] Geschäftsguthaben-Transaktion würde zu einem negativen Geschäftsguthaben-Saldo führen"
|
||||
}
|
||||
""")); // @formatter:on
|
||||
}
|
||||
|
||||
+31
-21
@@ -1,10 +1,12 @@
|
||||
package net.hostsharing.hsadminng.hs.office.coopassets;
|
||||
|
||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRealEntity;
|
||||
import net.hostsharing.hsadminng.config.MessagesResourceConfig;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
import net.hostsharing.hsadminng.rbac.test.JsonBuilder;
|
||||
@@ -42,6 +44,7 @@ import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -49,7 +52,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsOfficeCoopAssetsTransactionController.class)
|
||||
@Import({ StrictMapper.class, JsonObjectMapperConfiguration.class, DisableSecurityConfig.class })
|
||||
@Import({ StrictMapper.class,
|
||||
MessagesResourceConfig.class,
|
||||
MessageTranslator.class,
|
||||
JsonObjectMapperConfiguration.class,
|
||||
DisableSecurityConfig.class })
|
||||
@ActiveProfiles("test")
|
||||
@RunWith(SpringRunner.class)
|
||||
class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
@@ -531,11 +538,12 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
enum BadRequestTestCases {
|
||||
MEMBERSHIP_UUID_MISSING(
|
||||
requestBody -> requestBody.without("membership.uuid"),
|
||||
"[membershipUuid must not be null but is \"null\"]"), // TODO.impl: should be membership.uuid, Spring validation-problem?
|
||||
// TODO.impl: should be membership.uuid, but the Hibernate validator does not use the name from @JsonProperty
|
||||
"[membershipUuid darf nicht null sein"), // bracket because it's from a list of violations
|
||||
|
||||
MEMBERSHIP_UUID_NOT_FOUND_OR_NOT_ACCESSIBLE(
|
||||
requestBody -> requestBody.with("membership.uuid", UNAVAILABLE_UUID),
|
||||
"membership.uuid " + UNAVAILABLE_UUID + " not found"),
|
||||
"membership.uuid \"" + UNAVAILABLE_UUID + "\" nicht gefunden"),
|
||||
|
||||
MEMBERSHIP_UUID_AND_MEMBER_NUMBER_MUST_NOT_BE_GIVEN_BOTH(
|
||||
requestBody -> requestBody
|
||||
@@ -543,92 +551,92 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
.with("assetValue", "-128.00")
|
||||
.with("adoptingMembership.uuid", UNAVAILABLE_UUID)
|
||||
.with("adoptingMembership.memberNumber", UNAVAILABLE_MEMBER_NUMBER),
|
||||
"either adoptingMembership.uuid or adoptingMembership.memberNumber can be given, not both"),
|
||||
"entweder adoptingMembership.uuid oder adoptingMembership.memberNumber muss angegeben werden, nicht beide"),
|
||||
|
||||
MEMBERSHIP_UUID_OR_MEMBER_NUMBER_MUST_BE_GIVEN(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", TRANSFER)
|
||||
.with("assetValue", "-128.00"),
|
||||
"either adoptingMembership.uuid or adoptingMembership.memberNumber must be given for transactionType=TRANSFER"),
|
||||
"für transactionType=TRANSFER muss entweder adoptingMembership.uuid oder adoptingMembership.memberNumber angegeben werden"),
|
||||
|
||||
REVERSAL_ASSET_TRANSACTION_REQUIRES_REVERTED_ASSET_TX_UUID(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", REVERSAL)
|
||||
.with("assetValue", "-128.00"),
|
||||
"REVERSAL asset transaction requires revertedAssetTx.uuid"),
|
||||
"eine REVERSAL Geschäftsguthaben-Transaktion erfordert die Angabe einer revertedAssetTx.uuid"),
|
||||
|
||||
REVERSAL_ASSET_TRANSACTION_REQUIRES_AVAILABLE_REVERTED_ASSET_TX_UUID(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", REVERSAL)
|
||||
.with("assetValue", "-128.00")
|
||||
.with("revertedAssetTx.uuid", UNAVAILABLE_UUID),
|
||||
"revertedAssetTx.uuid " + UNAVAILABLE_UUID + " not found"),
|
||||
"revertedAssetTx.uuid \"" + UNAVAILABLE_UUID + "\" nicht gefunden"),
|
||||
|
||||
REVERSAL_ASSET_TRANSACTION_MUST_NEGATE_VALUE_OF_REVERTED_ASSET_TX(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", REVERSAL)
|
||||
.with("assetValue", "128.00")
|
||||
.with("revertedAssetTx.uuid", SOME_EXISTING_LOSS_ASSET_TX_UUID),
|
||||
"given assetValue=128.00 but must be negative value from reverted asset tx: -64"),
|
||||
"assetValue=128,00 muss dem negativen Wert des Wertes der stornierten Geschäftsguthaben-Transaktion entsprechen: -64,00"),
|
||||
|
||||
TRANSACTION_TYPE_MISSING(
|
||||
requestBody -> requestBody.without("transactionType"),
|
||||
"[transactionType must not be null but is \"null\"]"),
|
||||
"[transactionType darf nicht null sein"),
|
||||
|
||||
VALUE_DATE_MISSING(
|
||||
requestBody -> requestBody.without("valueDate"),
|
||||
"[valueDate must not be null but is \"null\"]"),
|
||||
"[valueDate darf nicht null sein"),
|
||||
|
||||
ASSETS_VALUE_FOR_DEPOSIT_MUST_BE_POSITIVE(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", DEPOSIT)
|
||||
.with("assetValue", -64.00),
|
||||
"[for DEPOSIT, assetValue must be positive but is \"-64.00\"]"),
|
||||
"[für transactionType=DEPOSIT, muss assetValue positiv sein, ist aber -64,00]"),
|
||||
|
||||
ASSETS_VALUE_FOR_DISBURSAL_MUST_BE_NEGATIVE(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", DISBURSAL)
|
||||
.with("assetValue", 64.00),
|
||||
"[for DISBURSAL, assetValue must be negative but is \"64.00\"]"),
|
||||
"[für transactionType=DISBURSAL, muss assetValue negativ sein, ist aber 64,00]"),
|
||||
|
||||
ADOPTING_MEMBERSHIP_MUST_NOT_BE_THE_SAME(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", TRANSFER)
|
||||
.with("assetValue", -64.00)
|
||||
.with("adoptingMembership.uuid", ORIGIN_MEMBERSHIP_UUID),
|
||||
"transferring and adopting membership must be different, but both are M-1111100"),
|
||||
"übertragende und annehmende Mitgliedschaft müssen unterschiedlich sein, aber beide sind M-1111100"),
|
||||
|
||||
ADOPTING_MEMBERSHIP_NUMBER_FOR_TRANSFER_MUST_BE_GIVEN_AND_AVAILABLE(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", TRANSFER)
|
||||
.with("assetValue", -64.00)
|
||||
.with("adoptingMembership.memberNumber", UNAVAILABLE_MEMBER_NUMBER),
|
||||
"adoptingMembership.memberNumber='M-1234699' not found or not accessible"),
|
||||
"adoptingMembership.memberNumber \"M-1234699\" nicht gefunden oder nicht zugänglich"),
|
||||
|
||||
ADOPTING_MEMBERSHIP_UUID_FOR_TRANSFER_MUST_BE_GIVEN_AND_AVAILABLE(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", TRANSFER)
|
||||
.with("assetValue", -64.00)
|
||||
.with("adoptingMembership.uuid", UNAVAILABLE_UUID),
|
||||
"adoptingMembership.uuid='" + UNAVAILABLE_UUID + "' not found or not accessible"),
|
||||
"adoptingMembership.uuid \"" + UNAVAILABLE_UUID + "\" nicht gefunden oder nicht zugänglich"),
|
||||
|
||||
ASSETS_VALUE_MUST_NOT_BE_NULL(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", REVERSAL)
|
||||
.with("assetValue", 0.00),
|
||||
"[assetValue must not be 0 but is \"0.00\"]"),
|
||||
"[assetValue darf nicht 0 sein]"),
|
||||
|
||||
REFERENCE_MISSING(
|
||||
requestBody -> requestBody.without("reference"),
|
||||
"[reference must not be null but is \"null\"]"),
|
||||
"[reference darf nicht null sein"),
|
||||
|
||||
REFERENCE_TOO_SHORT(
|
||||
requestBody -> requestBody.with("reference", "12345"),
|
||||
"[reference size must be between 6 and 48 but is \"12345\"]"),
|
||||
"[reference Größe muss zwischen 6 und 48 sein"), // OpenAPI Spring templates uses @Size, but should use @Length
|
||||
|
||||
REFERENCE_TOO_LONG(
|
||||
requestBody -> requestBody.with("reference", "0123456789012345678901234567890123456789012345678"),
|
||||
"[reference size must be between 6 and 48 but is \"0123456789012345678901234567890123456789012345678\"]");
|
||||
"[reference Größe muss zwischen 6 und 48 sein"); // OpenAPI Spring templates uses @Size, but should use @Length
|
||||
|
||||
private final Function<JsonBuilder, JsonBuilder> givenBodyTransformation;
|
||||
private final String expectedErrorMessage;
|
||||
@@ -652,12 +660,13 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
// - set SINGLE_TEST_CASE_EXECUTION to true - see above
|
||||
// - select the test case enum value you want to run
|
||||
assumeThat(!SINGLE_TEST_CASE_EXECUTION ||
|
||||
testCase == BadRequestTestCases.ADOPTING_MEMBERSHIP_MUST_NOT_BE_THE_SAME).isTrue();
|
||||
testCase == BadRequestTestCases.MEMBERSHIP_UUID_OR_MEMBER_NUMBER_MUST_BE_GIVEN).isTrue();
|
||||
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/coopassetstransactions")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(testCase.givenRequestBody())
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
@@ -665,7 +674,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
// then
|
||||
.andExpect(jsonPath("statusCode", is(400)))
|
||||
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
|
||||
.andExpect(jsonPath("message", is("ERROR: [400] " + testCase.expectedErrorMessage)))
|
||||
.andExpect(jsonPath("message", startsWith("ERROR: [400] " + testCase.expectedErrorMessage)))
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@@ -944,4 +953,5 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
private String suffixOf(final String memberNumber) {
|
||||
return memberNumber.substring("M-".length() + 5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
-11
@@ -1,5 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.coopshares;
|
||||
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
@@ -20,12 +21,13 @@ import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static net.hostsharing.hsadminng.rbac.test.JsonBuilder.jsonObject;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsOfficeCoopSharesTransactionController.class)
|
||||
@Import(DisableSecurityConfig.class)
|
||||
@Import({DisableSecurityConfig.class, MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
class HsOfficeCoopSharesTransactionControllerRestTest {
|
||||
|
||||
@@ -59,45 +61,45 @@ class HsOfficeCoopSharesTransactionControllerRestTest {
|
||||
enum BadRequestTestCases {
|
||||
MEMBERSHIP_UUID_MISSING(
|
||||
requestBody -> requestBody.without("membership.uuid"),
|
||||
"[membershipUuid must not be null but is \"null\"]"),
|
||||
"membershipUuid must not be null"),
|
||||
|
||||
TRANSACTION_TYPE_MISSING(
|
||||
requestBody -> requestBody.without("transactionType"),
|
||||
"[transactionType must not be null but is \"null\"]"),
|
||||
"transactionType must not be null"),
|
||||
|
||||
VALUE_DATE_MISSING(
|
||||
requestBody -> requestBody.without("valueDate"),
|
||||
"[valueDate must not be null but is \"null\"]"),
|
||||
"valueDate must not be null"),
|
||||
|
||||
SHARES_COUNT_FOR_SUBSCRIPTION_MUST_BE_POSITIVE(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", "SUBSCRIPTION")
|
||||
.with("shareCount", -1),
|
||||
"[for SUBSCRIPTION, shareCount must be positive but is \"-1\"]"),
|
||||
"for SUBSCRIPTION, shareCount must be positive but is \"-1\""),
|
||||
|
||||
SHARES_COUNT_FOR_CANCELLATION_MUST_BE_NEGATIVE(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", "CANCELLATION")
|
||||
.with("shareCount", 1),
|
||||
"[for CANCELLATION, shareCount must be negative but is \"1\"]"),
|
||||
"for CANCELLATION, shareCount must be negative but is \"1\""),
|
||||
|
||||
SHARES_COUNT_MUST_NOT_BE_NULL(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", "REVERSAL")
|
||||
.with("shareCount", 0),
|
||||
"[shareCount must not be 0 but is \"0\"]"),
|
||||
"shareCount must not be 0 but is \"0\""),
|
||||
|
||||
REFERENCE_MISSING(
|
||||
requestBody -> requestBody.without("reference"),
|
||||
"[reference must not be null but is \"null\"]"),
|
||||
"reference must not be null"),
|
||||
|
||||
REFERENCE_TOO_SHORT(
|
||||
requestBody -> requestBody.with("reference", "12345"),
|
||||
"[reference size must be between 6 and 48 but is \"12345\"]"),
|
||||
"reference size must be between 6 and 48 but is \"12345\""),
|
||||
|
||||
REFERENCE_TOO_LONG(
|
||||
requestBody -> requestBody.with("reference", "0123456789012345678901234567890123456789012345678"),
|
||||
"[reference size must be between 6 and 48 but is \"0123456789012345678901234567890123456789012345678\"]");
|
||||
"reference size must be between 6 and 48 but is \"0123456789012345678901234567890123456789012345678\"");
|
||||
|
||||
private final Function<JsonBuilder, JsonBuilder> givenBodyTransformation;
|
||||
private final String expectedErrorMessage;
|
||||
@@ -130,7 +132,7 @@ class HsOfficeCoopSharesTransactionControllerRestTest {
|
||||
.andExpect(status().is4xxClientError())
|
||||
.andExpect(jsonPath("statusCode", is(400)))
|
||||
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
|
||||
.andExpect(jsonPath("message", is("ERROR: [400] " + testCase.expectedErrorMessage)));
|
||||
.andExpect(jsonPath("message", containsString(testCase.expectedErrorMessage)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-3
@@ -1,5 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.membership;
|
||||
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRbacEntity;
|
||||
@@ -30,13 +31,14 @@ import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsOfficeMembershipController.class)
|
||||
@Import({StrictMapper.class, DisableSecurityConfig.class})
|
||||
@Import({StrictMapper.class, DisableSecurityConfig.class, MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
public class HsOfficeMembershipControllerRestTest {
|
||||
|
||||
@@ -74,6 +76,9 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
@MockitoBean
|
||||
Context contextMock;
|
||||
|
||||
@Autowired
|
||||
MessageTranslator messageTranslator;
|
||||
|
||||
@MockitoBean
|
||||
HsOfficeCoopAssetsTransactionRepository coopAssetsTransactionRepo;
|
||||
|
||||
@@ -249,7 +254,7 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
.andExpect(jsonPath("statusCode", is(400)))
|
||||
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
|
||||
// FYI: the brackets around the message are here because it's actually an array, in this case of size 1
|
||||
.andExpect(jsonPath("message", is("ERROR: [400] [partnerUuid must not be null but is \"null\"]")));
|
||||
.andExpect(jsonPath("message", startsWith("ERROR: [400] [partnerUuid must not be null")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -310,7 +315,7 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
}
|
||||
|
||||
public enum InvalidMemberSuffixVariants {
|
||||
MISSING("", "[memberNumberSuffix must not be null but is \"null\"]"),
|
||||
MISSING("", "[memberNumberSuffix must not be null"),
|
||||
TOO_SMALL("\"memberNumberSuffix\": \"9\",", "memberNumberSuffix must match \"[0-9]{2}\" but is \"9\""),
|
||||
TOO_LARGE("\"memberNumberSuffix\": \"100\",", "memberNumberSuffix must match \"[0-9]{2}\" but is \"100\""),
|
||||
NOT_NUMERIC("\"memberNumberSuffix\": \"AA\",", "memberNumberSuffix must match \"[0-9]{2}\" but is \"AA\""),
|
||||
|
||||
+35
-19
@@ -1,5 +1,7 @@
|
||||
package net.hostsharing.hsadminng.hs.office.partner;
|
||||
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactFromResourceConverter;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
|
||||
@@ -8,17 +10,18 @@ import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.config.MessagesResourceConfig;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
@@ -30,7 +33,7 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
@@ -39,7 +42,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsOfficePartnerController.class)
|
||||
@Import({ StrictMapper.class, HsOfficeContactFromResourceConverter.class, DisableSecurityConfig.class})
|
||||
@Import({ StrictMapper.class,
|
||||
MessagesResourceConfig.class,
|
||||
MessageTranslator.class,
|
||||
HsOfficeContactFromResourceConverter.class,
|
||||
DisableSecurityConfig.class })
|
||||
@ActiveProfiles("test")
|
||||
class HsOfficePartnerControllerRestTest {
|
||||
|
||||
@@ -54,6 +61,12 @@ class HsOfficePartnerControllerRestTest {
|
||||
@MockitoBean
|
||||
Context contextMock;
|
||||
|
||||
@Autowired
|
||||
MessageSource messageSource;
|
||||
|
||||
@Autowired
|
||||
MessageTranslator translator;
|
||||
|
||||
@MockitoBean
|
||||
HsOfficePartnerRbacRepository partnerRepo;
|
||||
|
||||
@@ -100,6 +113,7 @@ class HsOfficePartnerControllerRestTest {
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/partners")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
@@ -124,7 +138,8 @@ class HsOfficePartnerControllerRestTest {
|
||||
.andExpect(status().is4xxClientError())
|
||||
.andExpect(jsonPath("statusCode", is(400)))
|
||||
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
|
||||
.andExpect(jsonPath("message", startsWith("ERROR: [400] Cannot resolve HsOfficePersonRealEntity with uuid ")));
|
||||
.andExpect(jsonPath("message", equalTo(
|
||||
"ERROR: [400] RealPerson \"00000000-0000-0000-0000-000000000000\" nicht gefunden")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,7 +172,8 @@ class HsOfficePartnerControllerRestTest {
|
||||
.andExpect(status().is4xxClientError())
|
||||
.andExpect(jsonPath("statusCode", is(400)))
|
||||
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
|
||||
.andExpect(jsonPath("message", startsWith("ERROR: [400] Cannot resolve HsOfficeContactRealEntity with uuid ")));
|
||||
.andExpect(jsonPath("message", equalTo(
|
||||
"ERROR: [400] RealContact \"00000000-0000-0000-0000-000000000000\" not found")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,14 +189,14 @@ class HsOfficePartnerControllerRestTest {
|
||||
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/partners/P-12345")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.get("/api/hs/office/partners/P-12345")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("partnerNumber", is("P-12345")));
|
||||
// then
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("partnerNumber", is("P-12345")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,13 +206,13 @@ class HsOfficePartnerControllerRestTest {
|
||||
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/partners/P-12345")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.get("/api/hs/office/partners/P-12345")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
.andExpect(status().isNotFound());
|
||||
// then
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -273,7 +273,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
||||
void shouldCreateSelfDebitorForPartnerWithIdenticalContactData() {
|
||||
new CreateSelfDebitorForPartnerWithIdenticalContactData(scenarioTest)
|
||||
.given("partnerNumber", "P-31011")
|
||||
.given("debitorNumberSuffix", "00") // TODO.impl: could be assigned automatically, but is not yet
|
||||
.given("debitorNumberSuffix", "00") // TODO.impl: could be assigned automatically but is not yet
|
||||
.given("billable", true)
|
||||
.given("vatBusiness", false)
|
||||
.given("vatReverseCharge", false)
|
||||
@@ -291,7 +291,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
||||
.given("partnerPersonTradeName", "Test AG")
|
||||
.given("billingContactCaption", "Test AG - billing department")
|
||||
.given("billingContactEmailAddress", "billing@test-ag.example.org")
|
||||
.given("debitorNumberSuffix", "00") // TODO.impl: could be assigned automatically, but is not yet
|
||||
.given("debitorNumberSuffix", "00") // TODO.impl: could be assigned automaticallybut is not yet
|
||||
.given("billable", true)
|
||||
.given("vatId", "VAT123456")
|
||||
.given("vatCountryCode", "DE")
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package net.hostsharing.hsadminng.ping;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = {
|
||||
HsadminNgApplication.class,
|
||||
DisableSecurityConfig.class,
|
||||
JpaAttempt.class
|
||||
}
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
@Tag("generalIntegrationTest")
|
||||
class PingControllerAcceptanceTest {
|
||||
|
||||
@LocalServerPort
|
||||
private Integer port;
|
||||
|
||||
@Autowired
|
||||
Context context;
|
||||
|
||||
@Autowired
|
||||
Context contextMock;
|
||||
|
||||
enum PingTranslationTestCase {
|
||||
EN(Locale.ENGLISH, "pong superuser-alex@hostsharing.net - in English"),
|
||||
DE(Locale.GERMAN, "pong superuser-alex@hostsharing.net - auf Deutsch"),
|
||||
FR(Locale.FRENCH, "pong superuser-alex@hostsharing.net - in English [fr translation missing]");
|
||||
|
||||
Locale givenLocale;
|
||||
CharSequence expectedPongTranslation;
|
||||
|
||||
PingTranslationTestCase(final Locale givenLocale, final String expectedPongTranslation) {
|
||||
this.givenLocale = givenLocale;
|
||||
this.expectedPongTranslation = expectedPongTranslation;
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(PingTranslationTestCase.class)
|
||||
void pingRepliesWithTranslatedPongResponse(final PingTranslationTestCase testCase) {
|
||||
final var responseBody = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Accept-Language", testCase.givenLocale)
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/ping")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("text/plain;charset=UTF-8")
|
||||
.extract().body().asString();
|
||||
// @formatter:on
|
||||
|
||||
assertThat(responseBody).isEqualTo(testCase.expectedPongTranslation + "\n");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package net.hostsharing.hsadminng.ping;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.config.MessagesResourceConfig;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(PingController.class)
|
||||
@Import({ MessagesResourceConfig.class,
|
||||
MessageTranslator.class,
|
||||
JsonObjectMapperConfiguration.class,
|
||||
DisableSecurityConfig.class })
|
||||
@RunWith(SpringRunner.class)
|
||||
@ActiveProfiles("test")
|
||||
class PingControllerRestTest {
|
||||
|
||||
@Autowired
|
||||
MockMvc mockMvc;
|
||||
|
||||
@MockitoBean
|
||||
Context contextMock;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
enum I18nTestCases {
|
||||
EN("en", "pong anonymousUser - in English"),
|
||||
DE("de", "pong anonymousUser - auf Deutsch");
|
||||
|
||||
final String language;
|
||||
final String expectedTranslation;
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(I18nTestCases.class)
|
||||
void pingReturnsPongInEnglish(final I18nTestCases testCase) throws Exception {
|
||||
|
||||
// when
|
||||
final var request = mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/ping")
|
||||
.header("Accept-Language", testCase.language)
|
||||
.accept(MediaType.TEXT_PLAIN))
|
||||
.andDo(print());
|
||||
|
||||
// then
|
||||
request
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(startsWith(testCase.expectedTranslation)));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.hostsharing.hsadminng.rbac.role;
|
||||
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
@@ -31,7 +32,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(RbacRoleController.class)
|
||||
@Import({StrictMapper.class, DisableSecurityConfig.class})
|
||||
@Import({StrictMapper.class, DisableSecurityConfig.class, MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
@RunWith(SpringRunner.class)
|
||||
class RbacRoleControllerRestTest {
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package net.hostsharing.hsadminng.rbac.subject;
|
||||
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
@@ -27,7 +28,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(RbacSubjectController.class)
|
||||
@Import({StrictMapper.class, DisableSecurityConfig.class})
|
||||
@Import({StrictMapper.class, DisableSecurityConfig.class, MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
@RunWith(SpringRunner.class)
|
||||
class RbacSubjectControllerRestTest {
|
||||
|
||||
Reference in New Issue
Block a user