Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit df243dc3 authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

Update test

parent 47d661bd
No related branches found
No related tags found
No related merge requests found
Pipeline #23765 passed with warnings
......@@ -19,6 +19,8 @@ import eu.europa.ec.edelivery.smp.data.model.*;
import eu.europa.ec.edelivery.smp.data.ui.enums.SMPPropertyEnum;
import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException;
import eu.europa.ec.edelivery.smp.testutil.TestConstants;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.hamcrest.core.StringStartsWith;
import org.junit.Before;
import org.junit.Rule;
......@@ -54,9 +56,6 @@ public class ServiceGroupServiceSingleDomainIntegrationTest extends AbstractServ
@Autowired
protected ServiceGroupService testInstance;
@Rule
public ExpectedException expectedExeption = ExpectedException.none();
@Before
@Transactional
public void prepareDatabase() {
......@@ -162,11 +161,11 @@ public class ServiceGroupServiceSingleDomainIntegrationTest extends AbstractServ
@Test
public void serviceGroupNotExistsWhenRetrievingSG() {
// given
expectedExeption.expect(SMPRuntimeException.class);
expectedExeption.expectMessage(SG_NOT_EXISTS.getMessage("service-group", "not-existing"));
// when-then
testInstance.getServiceGroup(new ParticipantIdentifierType("service-group","not-existing") );
SMPRuntimeException result = assertThrows(SMPRuntimeException.class,
()->testInstance.getServiceGroup(new ParticipantIdentifierType("not-existing", "bad-srv-grp") ));
assertEquals(SG_NOT_EXISTS.getMessage("not-existing", "bad-srv-grp"), result.getMessage());
}
@Test
......@@ -182,13 +181,10 @@ public class ServiceGroupServiceSingleDomainIntegrationTest extends AbstractServ
testInstance.deleteServiceGroup(inServiceGroup.getParticipantIdentifier());
serviceGroupDao.clearPersistenceContext();
//then
expectedExeption.expect(SMPRuntimeException.class);
// get by null domain so: (all registered domains)
expectedExeption.expectMessage(SG_NOT_EXISTS.getMessage( inServiceGroup.getParticipantIdentifier().getValue(),
inServiceGroup.getParticipantIdentifier().getScheme()));
ServiceGroup sg = testInstance.getServiceGroup(inServiceGroup.getParticipantIdentifier());
SMPRuntimeException result = assertThrows(SMPRuntimeException.class,
()->testInstance.getServiceGroup(inServiceGroup.getParticipantIdentifier()));
assertEquals(SG_NOT_EXISTS.getMessage( inServiceGroup.getParticipantIdentifier().getValue(), inServiceGroup.getParticipantIdentifier().getScheme())
, result.getMessage());
}
......@@ -222,16 +218,13 @@ public class ServiceGroupServiceSingleDomainIntegrationTest extends AbstractServ
assertTrue(dbUser.isPresent()); // test if exists
assertFalse(dbsg.get().getUsers().contains(dbUser.get())); // test not owner
//then
expectedExeption.expect(SMPRuntimeException.class);
// get by null domain so: (all registered domains)
expectedExeption.expectMessage(USER_IS_NOT_OWNER.getMessage(TestConstants.USER_CERT_2,
dbsg.get().getParticipantIdentifier(), dbsg.get().getParticipantScheme()));
// when
testInstance.saveServiceGroup(inServiceGroup,null,
TestConstants.USER_CERT_2, TestConstants.USER_CERT_2);
SMPRuntimeException result = assertThrows(SMPRuntimeException.class,
()->testInstance.saveServiceGroup(inServiceGroup,null,
TestConstants.USER_CERT_2, TestConstants.USER_CERT_2));
assertEquals(USER_IS_NOT_OWNER.getMessage(TestConstants.USER_CERT_2,
dbsg.get().getParticipantIdentifier(), dbsg.get().getParticipantScheme()), result.getMessage());
}
@Test
......@@ -243,15 +236,12 @@ public class ServiceGroupServiceSingleDomainIntegrationTest extends AbstractServ
Optional<DBUser> dbUser = userDao.findUserByIdentifier(TestConstants.USER_CERT_3);
assertTrue(dbsg.isPresent()); // test if note exists
assertFalse(dbUser.isPresent()); // test if exists
//then
expectedExeption.expect(SMPRuntimeException.class);
// get by null domain so: (all registered domains)
expectedExeption.expectMessage(INVALID_OWNER.getMessage(TestConstants.USER_CERT_3));
// when
testInstance.saveServiceGroup(inServiceGroup, null,
TestConstants.USER_CERT_3, TestConstants.USER_CERT_3);
SMPRuntimeException result = assertThrows(SMPRuntimeException.class,
()->testInstance.saveServiceGroup(inServiceGroup, null,
TestConstants.USER_CERT_3, TestConstants.USER_CERT_3));
assertEquals(INVALID_OWNER.getMessage(TestConstants.USER_CERT_3), result.getMessage());
}
@Test
......@@ -259,12 +249,12 @@ public class ServiceGroupServiceSingleDomainIntegrationTest extends AbstractServ
String username = "test::20%atest";
//given
ServiceGroup inServiceGroup = unmarshal(loadDocumentAsString(TestConstants.SERVICE_GROUP_TEST2_XML_PATH));
expectedExeption.expect(SMPRuntimeException.class);
expectedExeption.expectMessage(StringStartsWith.startsWith("Unsupported or invalid encoding"));
//when
testInstance.saveServiceGroup(inServiceGroup, null, username, username);
SMPRuntimeException result = assertThrows(SMPRuntimeException.class,
()->testInstance.saveServiceGroup(inServiceGroup, null, username, username));
MatcherAssert.assertThat(result.getMessage(), CoreMatchers.startsWith("Unsupported or invalid encoding"));
}
@Test
......@@ -272,11 +262,12 @@ public class ServiceGroupServiceSingleDomainIntegrationTest extends AbstractServ
//given
String domain="NOTEXISTINGDOMAIN";
ServiceGroup inServiceGroup = unmarshal(loadDocumentAsString(TestConstants.SERVICE_GROUP_POLAND_XML_PATH));
expectedExeption.expect(SMPRuntimeException.class);
expectedExeption.expectMessage(DOMAIN_NOT_EXISTS.getMessage(domain));
//execute
testInstance.saveServiceGroup(inServiceGroup, domain, USERNAME_TOKEN_1, USERNAME_TOKEN_1);
SMPRuntimeException result = assertThrows(SMPRuntimeException.class,
()->testInstance.saveServiceGroup(inServiceGroup, domain, USERNAME_TOKEN_1, USERNAME_TOKEN_1));
assertEquals(DOMAIN_NOT_EXISTS.getMessage(domain), result.getMessage());
}
@Test
......@@ -284,12 +275,13 @@ public class ServiceGroupServiceSingleDomainIntegrationTest extends AbstractServ
//given
String domain="notAllowedChars:-_;#$";
ServiceGroup inServiceGroup = unmarshal(loadDocumentAsString(TestConstants.SERVICE_GROUP_POLAND_XML_PATH));
expectedExeption.expect(SMPRuntimeException.class);
expectedExeption.expectMessage(INVALID_DOMAIN_CODE.getMessage(domain,
DomainService.DOMAIN_ID_PATTERN.pattern()));
//execute
testInstance.saveServiceGroup(inServiceGroup, domain, USERNAME_TOKEN_1, USERNAME_TOKEN_1);
SMPRuntimeException result = assertThrows(SMPRuntimeException.class,
()->testInstance.saveServiceGroup(inServiceGroup, domain, USERNAME_TOKEN_1, USERNAME_TOKEN_1));
assertEquals(INVALID_DOMAIN_CODE.getMessage(domain,
DomainService.DOMAIN_ID_PATTERN.pattern()), result.getMessage());
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment