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 ec98c7dc authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

add tests from SMLIntegration

parent e75c401c
No related branches found
No related tags found
No related merge requests found
......@@ -85,7 +85,7 @@ public class SmlConnector implements ApplicationContextAware {
}
}
private boolean processSMLErrorMessage(BadRequestFault e, ParticipantIdentifierType participantIdentifierType){
protected boolean processSMLErrorMessage(BadRequestFault e, ParticipantIdentifierType participantIdentifierType){
if(!isOkMessage(participantIdentifierType, e.getMessage())){
LOG.error( e.getMessage(), e);
throw new SMPRuntimeException(ErrorCode.SML_INTEGRATION_EXCEPTION,e, ExceptionUtils.getRootCauseMessage(e));
......@@ -94,7 +94,7 @@ public class SmlConnector implements ApplicationContextAware {
return true;
}
private boolean processSMLErrorMessage(NotFoundFault e, ParticipantIdentifierType participantIdentifierType){
protected boolean processSMLErrorMessage(NotFoundFault e, ParticipantIdentifierType participantIdentifierType){
if(!isOkMessage(participantIdentifierType, e.getMessage())){
LOG.error( e.getMessage(), e);
throw new SMPRuntimeException(ErrorCode.SML_INTEGRATION_EXCEPTION,e, ExceptionUtils.getRootCauseMessage(e));
......
......@@ -11,42 +11,31 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.smlintegration;
package eu.europa.ec.edelivery.smp.sml;
import eu.europa.ec.bdmsl.ws.soap.IManageParticipantIdentifierWS;
import eu.europa.ec.bdmsl.ws.soap.IManageServiceMetadataWS;
import eu.europa.ec.edelivery.smp.config.ConversionTestConfig;
import eu.europa.ec.edelivery.smp.config.PropertiesMultipleDomainTestConfig;
import eu.europa.ec.edelivery.smp.config.PropertiesSingleDomainTestConfig;
import eu.europa.ec.edelivery.smp.services.SecurityUtilsServices;
import eu.europa.ec.edelivery.smp.services.ui.UIKeystoreService;
import eu.europa.ec.edelivery.smp.sml.SmlClientFactory;
import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.message.Message;
import org.apache.cxf.transport.http.HTTPConduit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.net.ssl.KeyManager;
import javax.net.ssl.X509KeyManager;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.PrivateKey;
import java.security.Security;
import java.security.cert.X509Certificate;
import java.util.Map;
import static eu.europa.ec.edelivery.smp.testutil.LocalPropertiesTestUtil.buildLocalProperties;
import static org.junit.Assert.*;
/**
......
......@@ -11,7 +11,7 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.smlintegration;
package eu.europa.ec.edelivery.smp.sml;
import eu.europa.ec.bdmsl.ws.soap.IManageParticipantIdentifierWS;
import eu.europa.ec.bdmsl.ws.soap.IManageServiceMetadataWS;
......@@ -19,24 +19,18 @@ import eu.europa.ec.edelivery.smp.config.ConversionTestConfig;
import eu.europa.ec.edelivery.smp.config.PropertiesSingleDomainTestConfig;
import eu.europa.ec.edelivery.smp.services.SecurityUtilsServices;
import eu.europa.ec.edelivery.smp.services.ui.UIKeystoreService;
import eu.europa.ec.edelivery.smp.sml.SmlClientFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.message.Message;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.convert.ConversionService;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import java.util.Map;
import static eu.europa.ec.edelivery.smp.testutil.LocalPropertiesTestUtil.buildLocalProperties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
......
......@@ -11,38 +11,34 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.smlintegration;
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.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.sml.SmlClientFactory;
import eu.europa.ec.edelivery.smp.sml.SmlConnector;
import org.junit.Before;
import eu.europa.ec.edelivery.smp.testutil.TestDBUtils;
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.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE;
/**
* Created by gutowpa on 08/01/2018.
......@@ -66,6 +62,14 @@ public class SmlConnectorTest {
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";
@Rule
public ExpectedException expectedExeption = ExpectedException.none();
@Autowired
SmlIntegrationConfiguration mockSml;
......@@ -126,4 +130,88 @@ public class SmlConnectorTest {
verify(mockSml.getParticipantManagmentClientMocks().get(1)).delete(any());
Mockito.verifyNoMoreInteractions(mockSml.getParticipantManagmentClientMocks().toArray());
}
@Test
public void testIsOkMessageForParticipantNull(){
boolean suc = smlConnector.isOkMessage(PARTICIPANT_ID, null);
assertFalse(suc);
}
@Test
public void testIsOkMessageForParticipantOk(){
boolean suc = smlConnector.isOkMessage(PARTICIPANT_ID, ERROR_PI_ALREADY_EXISTS);
assertTrue(suc);
}
@Test
public void testIsOkMessageForParticipantFalse(){
boolean suc = smlConnector.isOkMessage(PARTICIPANT_ID, ERROR_UNEXPECTED_MESSAGE);
assertFalse(suc);
}
@Test
public void testIsOkMessageForDomainNull(){
boolean suc = smlConnector.isOkMessage(DEFAULT_DOMAIN, null);
assertFalse(suc);
}
@Test
public void testIsOkMessageForParticipantOkAdd(){
boolean suc = smlConnector.isOkMessage(DEFAULT_DOMAIN, ERROR_SMP_ALREADY_EXISTS);
assertTrue(suc);
}
@Test
public void testIsOkMessageForParticipantOkDelete(){
boolean suc = smlConnector.isOkMessage(DEFAULT_DOMAIN, ERROR_SMP_NOT_EXISTS);
assertTrue(suc);
}
@Test
public void testIsOkMessageForDomainFalse(){
boolean suc = smlConnector.isOkMessage(DEFAULT_DOMAIN, ERROR_UNEXPECTED_MESSAGE);
assertFalse(suc);
}
@Test
public void testProcessSMLErrorMessageBadRequestFaultIgnore(){
BadRequestFault ex = new BadRequestFault(ERROR_PI_ALREADY_EXISTS);
boolean suc = smlConnector.processSMLErrorMessage(ex, PARTICIPANT_ID);
assertTrue(suc);
}
@Test
public void testProcessSMLErrorMessageBadRequestFaultFailed(){
expectedExeption.expectMessage(ERROR_UNEXPECTED_MESSAGE);
expectedExeption.expect(SMPRuntimeException .class);
BadRequestFault ex = new BadRequestFault(ERROR_UNEXPECTED_MESSAGE);
smlConnector.processSMLErrorMessage(ex, PARTICIPANT_ID);
}
@Test
public void testProcessSMLErrorMessageNoFoundFaultFailed(){
expectedExeption.expectMessage(ERROR_UNEXPECTED_MESSAGE);
expectedExeption.expect(SMPRuntimeException .class);
NotFoundFault ex = new NotFoundFault(ERROR_UNEXPECTED_MESSAGE);
smlConnector.processSMLErrorMessage(ex, PARTICIPANT_ID);
}
}
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