Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

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

unit test for SML integration - fix for sonar

parent a04fb8ba
No related branches found
No related tags found
No related merge requests found
......@@ -6,8 +6,6 @@ import eu.europa.ec.edelivery.smp.config.SmlIntegrationConfiguration;
import eu.europa.ec.edelivery.smp.data.model.DBDomain;
import eu.europa.ec.edelivery.smp.services.SecurityUtilsServices;
import eu.europa.ec.edelivery.smp.services.ui.UIKeystoreService;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -18,7 +16,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { SmlConnector.class,SmlIntegrationConfiguration.class,
@ContextConfiguration(classes = {SmlConnector.class, SmlIntegrationConfiguration.class,
SecurityUtilsServices.class, UIKeystoreService.class,
ConversionTestConfig.class, PropertiesSingleDomainTestConfig.class})
@Configuration
......@@ -27,29 +25,23 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class SmlConnectorTestBase {
protected static final ParticipantIdentifierType PARTICIPANT_ID = new ParticipantIdentifierType("sample:value", "sample:scheme");
protected static final DBDomain DEFAULT_DOMAIN;
static {
DEFAULT_DOMAIN = new DBDomain();
DEFAULT_DOMAIN.setDomainCode("default_domain_id");
DEFAULT_DOMAIN.setSmlSmpId("SAMPLE-SMP-ID");
}
protected static final String ERROR_UNEXPECTED_MESSAGE ="[ERR-106] Something unexpected happend";
protected static final String ERROR_SMP_NOT_EXISTS ="[ERR-100] The SMP '"+DEFAULT_DOMAIN.getSmlSmpId()+"' doesn't exist";
protected static final String ERROR_SMP_ALREADY_EXISTS ="[ERR-106] The SMP '"+DEFAULT_DOMAIN.getSmlSmpId()+"' already exists";
protected static final String ERROR_PI_ALREADY_EXISTS = "[ERR-106] The participant identifier 'sample:value' does already exist for the scheme sample:scheme";
protected static final String ERROR_PI_NO_EXISTS = "[ERR-100] The participant identifier 'sample:value' doesn't exist for the scheme sample:scheme";
protected static final String ERROR_UNEXPECTED_MESSAGE = "[ERR-106] Something unexpected happend";
protected static final String ERROR_SMP_NOT_EXISTS = "[ERR-100] The SMP '" + DEFAULT_DOMAIN.getSmlSmpId() + "' doesn't exist";
protected static final String ERROR_SMP_ALREADY_EXISTS = "[ERR-106] The SMP '" + DEFAULT_DOMAIN.getSmlSmpId() + "' already exists";
protected static final String ERROR_PI_ALREADY_EXISTS = "[ERR-106] The participant identifier 'sample:value' does already exist for the scheme sample:scheme";
protected static final String ERROR_PI_NO_EXISTS = "[ERR-100] The participant identifier 'sample:value' doesn't exist for the scheme sample:scheme";
@Rule
public ExpectedException expectedExeption = ExpectedException.none();
@Autowired
protected SmlConnector smlConnector;
@Autowired
SmlIntegrationConfiguration mockSml;
@Autowired
public void setup(){
mockSml.reset();
}
}
......@@ -17,24 +17,13 @@ import eu.europa.ec.bdmsl.ws.soap.BadRequestFault;
import eu.europa.ec.bdmsl.ws.soap.InternalErrorFault;
import eu.europa.ec.bdmsl.ws.soap.NotFoundFault;
import eu.europa.ec.bdmsl.ws.soap.UnauthorizedFault;
import eu.europa.ec.edelivery.smp.config.ConversionTestConfig;
import eu.europa.ec.edelivery.smp.config.PropertiesSingleDomainTestConfig;
import eu.europa.ec.edelivery.smp.config.SmlIntegrationConfiguration;
import eu.europa.ec.edelivery.smp.data.model.DBDomain;
import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException;
import eu.europa.ec.edelivery.smp.services.SecurityUtilsServices;
import eu.europa.ec.edelivery.smp.services.ui.UIKeystoreService;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.*;
......@@ -46,35 +35,13 @@ import static org.mockito.Mockito.verify;
* since 4.1.
*/
@RunWith(SpringRunner.class)
public class SmlConnectorTestDomain extends SmlConnectorTestBase{
// private static List<IManageParticipantIdentifierWS> smlClientMocks = new ArrayList<>();
private static final ParticipantIdentifierType PARTICIPANT_ID = new ParticipantIdentifierType("sample:value", "sample:scheme");
private static final DBDomain DEFAULT_DOMAIN;
static {
DEFAULT_DOMAIN = new DBDomain();
DEFAULT_DOMAIN.setDomainCode("default_domain_id");
DEFAULT_DOMAIN.setSmlSmpId("SAMPLE-SMP-ID");
}
private static final String ERROR_UNEXPECTED_MESSAGE ="[ERR-106] Something unexpected happend";
private static final String ERROR_SMP_NOT_EXISTS ="[ERR-100] The SMP '"+DEFAULT_DOMAIN.getSmlSmpId()+"' doesn't exist";
private static final String ERROR_SMP_ALREADY_EXISTS ="[ERR-106] The SMP '"+DEFAULT_DOMAIN.getSmlSmpId()+"' already exists";
private static final String ERROR_PI_ALREADY_EXISTS = "[ERR-106] The participant identifier 'sample:value' does already exist for the scheme sample:scheme";
private static final String ERROR_PI_NO_EXISTS = "[ERR-100] The participant identifier 'sample:value' doesn't exist for the scheme sample:scheme";
public class SmlConnectorTestDomain extends SmlConnectorTestBase {
@Rule
public ExpectedException expectedExeption = ExpectedException.none();
@Autowired
SmlIntegrationConfiguration mockSml;
@Autowired
private SmlConnector smlConnector;
@Autowired
public void setup(){
@Before
public void setup() {
mockSml.reset();
}
......@@ -105,13 +72,13 @@ public class SmlConnectorTestDomain extends SmlConnectorTestBase{
}
@Test
public void testRegisterDomainInDnsUnknownException(){
public void testRegisterDomainInDnsUnknownException() {
//when
String message = "something unexpected";
Exception ex = new Exception(message);
mockSml.setThrowException(ex);
expectedExeption.expectMessage(message);
expectedExeption.expect(SMPRuntimeException .class);
expectedExeption.expect(SMPRuntimeException.class);
smlConnector.registerDomain(DEFAULT_DOMAIN);
}
......@@ -155,47 +122,47 @@ public class SmlConnectorTestDomain extends SmlConnectorTestBase{
}
@Test
public void testUnregisterDomainFromDnsThrowUnknownBadRequestFault() {
public void testUnregisterDomainFromDnsThrowUnknownBadRequestFault() {
//when
BadRequestFault ex = new BadRequestFault(ERROR_UNEXPECTED_MESSAGE);
mockSml.setThrowException(ex);
expectedExeption.expectMessage(ERROR_UNEXPECTED_MESSAGE);
expectedExeption.expect(SMPRuntimeException .class);
expectedExeption.expect(SMPRuntimeException.class);
smlConnector.unregisterDomain(DEFAULT_DOMAIN);
}
@Test
public void testUnregisterDomainFromDnsThrowUnknownException() {
@Test
public void testUnregisterDomainFromDnsThrowUnknownException() {
//when
String message = "something unexpected";
Exception ex = new Exception(message);
mockSml.setThrowException(ex);
expectedExeption.expectMessage(message);
expectedExeption.expect(SMPRuntimeException .class);
expectedExeption.expect(SMPRuntimeException.class);
smlConnector.unregisterDomain(DEFAULT_DOMAIN);
smlConnector.unregisterDomain(DEFAULT_DOMAIN);
}
@Test
public void testUnregisterDomainFromDnsNotExists() {
public void testUnregisterDomainFromDnsNotExists() {
//when
BadRequestFault ex = new BadRequestFault(ERROR_SMP_NOT_EXISTS);
mockSml.setThrowException(ex);
boolean suc = smlConnector.unregisterDomain(DEFAULT_DOMAIN);
boolean suc = smlConnector.unregisterDomain(DEFAULT_DOMAIN);
assertTrue(suc);
}
@Test
public void testIsOkMessageForDomainNull(){
public void testIsOkMessageForDomainNull() {
boolean suc = smlConnector.isOkMessage(DEFAULT_DOMAIN, null);
assertFalse(suc);
}
@Test
public void testIsOkMessageForDomainFalse(){
public void testIsOkMessageForDomainFalse() {
boolean suc = smlConnector.isOkMessage(DEFAULT_DOMAIN, ERROR_UNEXPECTED_MESSAGE);
......
......@@ -13,33 +13,21 @@
package eu.europa.ec.edelivery.smp.sml;
import eu.europa.ec.bdmsl.ws.soap.*;
import eu.europa.ec.edelivery.smp.config.ConversionTestConfig;
import eu.europa.ec.edelivery.smp.config.PropertiesSingleDomainTestConfig;
import eu.europa.ec.edelivery.smp.config.SmlIntegrationConfiguration;
import eu.europa.ec.edelivery.smp.data.model.DBDomain;
import eu.europa.ec.bdmsl.ws.soap.BadRequestFault;
import eu.europa.ec.bdmsl.ws.soap.InternalErrorFault;
import eu.europa.ec.bdmsl.ws.soap.NotFoundFault;
import eu.europa.ec.bdmsl.ws.soap.UnauthorizedFault;
import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException;
import eu.europa.ec.edelivery.smp.services.SecurityUtilsServices;
import eu.europa.ec.edelivery.smp.services.ui.UIKeystoreService;
import eu.europa.ec.edelivery.smp.testutil.TestDBUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.booleanThat;
import static org.mockito.Mockito.verify;
/**
......@@ -49,7 +37,13 @@ import static org.mockito.Mockito.verify;
@RunWith(SpringRunner.class)
public class SmlConnectorTestParticipant extends SmlConnectorTestBase {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setup() {
mockSml.reset();
}
@Test
public void testRegisterInDns() throws UnauthorizedFault, NotFoundFault, InternalErrorFault, BadRequestFault {
......@@ -83,8 +77,8 @@ public class SmlConnectorTestParticipant extends SmlConnectorTestBase {
String message = "something unexpected";
Exception ex = new Exception(message);
mockSml.setThrowException(ex);
expectedExeption.expectMessage(message);
expectedExeption.expect(SMPRuntimeException .class);
expectedException.expectMessage(message);
expectedException.expect(SMPRuntimeException.class);
smlConnector.registerInDns(PARTICIPANT_ID, DEFAULT_DOMAIN);
}
......@@ -128,41 +122,41 @@ public class SmlConnectorTestParticipant extends SmlConnectorTestBase {
}
@Test
public void testUnregisterFromDnsThrowUnknownBadRequestFault() {
public void testUnregisterFromDnsThrowUnknownBadRequestFault() {
//when
BadRequestFault ex = new BadRequestFault(ERROR_UNEXPECTED_MESSAGE);
mockSml.setThrowException(ex);
expectedExeption.expectMessage(ERROR_UNEXPECTED_MESSAGE);
expectedExeption.expect(SMPRuntimeException .class);
expectedException.expectMessage(ERROR_UNEXPECTED_MESSAGE);
expectedException.expect(SMPRuntimeException.class);
smlConnector.unregisterFromDns(PARTICIPANT_ID, DEFAULT_DOMAIN);
}
@Test
public void testUnregisterFromDnsThrowUnknownException() {
public void testUnregisterFromDnsThrowUnknownException() {
//when
String message = "something unexpected";
Exception ex = new Exception(message);
mockSml.setThrowException(ex);
expectedExeption.expectMessage(message);
expectedExeption.expect(SMPRuntimeException .class);
expectedException.expectMessage(message);
expectedException.expect(SMPRuntimeException.class);
smlConnector.unregisterFromDns(PARTICIPANT_ID, DEFAULT_DOMAIN);
}
@Test
public void testUnregisterFromDnsNotExists() {
public void testUnregisterFromDnsNotExists() {
//when
BadRequestFault ex = new BadRequestFault(ERROR_PI_NO_EXISTS);
mockSml.setThrowException(ex);
boolean suc = smlConnector.unregisterFromDns(PARTICIPANT_ID, DEFAULT_DOMAIN);
boolean suc = smlConnector.unregisterFromDns(PARTICIPANT_ID, DEFAULT_DOMAIN);
assertTrue(suc);
}
@Test
public void testIsOkMessageForParticipantNull(){
public void testIsOkMessageForParticipantNull() {
boolean suc = smlConnector.isOkMessage(PARTICIPANT_ID, null);
......@@ -170,14 +164,14 @@ public class SmlConnectorTestParticipant extends SmlConnectorTestBase {
}
@Test
public void testIsOkMessageForParticipantOk(){
public void testIsOkMessageForParticipantOk() {
boolean suc = smlConnector.isOkMessage(PARTICIPANT_ID, ERROR_PI_ALREADY_EXISTS);
assertTrue(suc);
}
@Test
public void testIsOkMessageForParticipantFalse(){
public void testIsOkMessageForParticipantFalse() {
boolean suc = smlConnector.isOkMessage(PARTICIPANT_ID, ERROR_UNEXPECTED_MESSAGE);
assertFalse(suc);
......@@ -185,19 +179,19 @@ public class SmlConnectorTestParticipant extends SmlConnectorTestBase {
@Test
public void testProcessSMLErrorMessageBadRequestFaultIgnore(){
public void testProcessSMLErrorMessageBadRequestFaultIgnore() {
BadRequestFault ex = new BadRequestFault(ERROR_PI_ALREADY_EXISTS);
boolean suc = smlConnector.processSMLErrorMessage(ex, PARTICIPANT_ID);
assertTrue(suc);
assertTrue(suc);
}
@Test
public void testProcessSMLErrorMessageBadRequestFaultFailed(){
public void testProcessSMLErrorMessageBadRequestFaultFailed() {
expectedExeption.expectMessage(ERROR_UNEXPECTED_MESSAGE);
expectedExeption.expect(SMPRuntimeException .class);
expectedException.expectMessage(ERROR_UNEXPECTED_MESSAGE);
expectedException.expect(SMPRuntimeException.class);
BadRequestFault ex = new BadRequestFault(ERROR_UNEXPECTED_MESSAGE);
smlConnector.processSMLErrorMessage(ex, PARTICIPANT_ID);
......@@ -205,17 +199,17 @@ public class SmlConnectorTestParticipant extends SmlConnectorTestBase {
@Test
public void testProcessSMLErrorMessageNoFoundFaultFailed(){
public void testProcessSMLErrorMessageNoFoundFaultFailed() {
expectedExeption.expectMessage(ERROR_UNEXPECTED_MESSAGE);
expectedExeption.expect(SMPRuntimeException .class);
expectedException.expectMessage(ERROR_UNEXPECTED_MESSAGE);
expectedException.expect(SMPRuntimeException.class);
NotFoundFault ex = new NotFoundFault(ERROR_UNEXPECTED_MESSAGE);
smlConnector.processSMLErrorMessage(ex, PARTICIPANT_ID);
}
@Test
public void testProcessSMLErrorMessageNoFoundFaultOk(){
public void testProcessSMLErrorMessageNoFoundFaultOk() {
NotFoundFault ex = new NotFoundFault(ERROR_PI_NO_EXISTS);
......@@ -223,5 +217,4 @@ public class SmlConnectorTestParticipant extends SmlConnectorTestBase {
}
}
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