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

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

add unit tests

parent 5826a36b
No related branches found
No related tags found
No related merge requests found
Pipeline #76953 passed with warnings
Showing
with 197 additions and 344 deletions
......@@ -102,10 +102,10 @@ public class SMPExtensionInitializer implements InitializingBean {
Optional<DBResourceDef> resourceDef = resourceDefDao.getResourceDefByIdentifier(resourceDefinitionSpi.identifier());
if (resourceDef.isPresent()) {
DBResourceDef dbResourceDef = resourceDef.get();
if (StringUtils.equals(extension.getIdentifier(),dbResourceDef.getExtension().getIdentifier() )) {
if (dbResourceDef.getExtension()!=null && StringUtils.equals(extension.getIdentifier(),dbResourceDef.getExtension().getIdentifier() )) {
updateResourceSPI(resourceDefinitionSpi, dbResourceDef);
} else {
LOG.error("Skip resource definition update due to extension missmatch! ResourceDefinition [{}] is already registered for extension [{}]. The current resource extension identifier is [{}]!",
LOG.error("Skip resource definition update due to extension mismatch! ResourceDefinition [{}] is already registered for extension [{}]. The current resource extension identifier is [{}]!",
resourceDefinitionSpi,
extension,
dbResourceDef.getExtension());
......
......@@ -134,28 +134,19 @@ public class UIDocumentService {
}
DBDocument document = resource.getDocument();
int version = document.getDocumentVersions().stream().mapToInt(dv -> dv.getVersion())
.max().orElse(0);
DBDocumentVersion documentVersion = new DBDocumentVersion();
documentVersion.setVersion(version + 1);
documentVersion.setDocument(document);
documentVersion.setContent(bos.toByteArray());
document.getDocumentVersions().add(documentVersion);
document.setCurrentVersion(documentVersion.getVersion());
return convert(document, documentVersion);
return createNewVersionAndConvert(document, bos);
}
@Transactional
public DocumentRo saveSubresourceDocumentForResource(Long subresource, Long resourceId, DocumentRo documentRo) {
DBResource parentResource = resourceDao.find(resourceId);
DBSubresource enitity = subresourceDao.find(subresource);
DBSubresourceDef subresourceDef = enitity.getSubresourceDef();
DBSubresource entity = subresourceDao.find(subresource);
DBSubresourceDef subresourceDef = entity.getSubresourceDef();
ResourceHandlerSpi resourceHandler = resourceHandlerService.getSubresourceHandler(subresourceDef, subresourceDef.getResourceDef());
RequestData data = resourceHandlerService.buildRequestDataForSubResource(
parentResource.getDomainResourceDef().getDomain(), parentResource,
enitity, new ByteArrayInputStream(documentRo.getPayload().getBytes()));
entity, new ByteArrayInputStream(documentRo.getPayload().getBytes()));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ResponseData responseData = new SpiResponseData(bos);
try {
......@@ -164,18 +155,8 @@ public class UIDocumentService {
throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, "StoreSubresourceValidation", ExceptionUtils.getRootCauseMessage(e));
}
DBDocument document = enitity.getDocument();
;
int version = document.getDocumentVersions().stream().mapToInt(dv -> dv.getVersion())
.max().orElse(0);
DBDocumentVersion documentVersion = new DBDocumentVersion();
documentVersion.setVersion(version + 1);
documentVersion.setDocument(document);
documentVersion.setContent(bos.toByteArray());
document.getDocumentVersions().add(documentVersion);
document.setCurrentVersion(documentVersion.getVersion());
return convert(document, documentVersion);
DBDocument document = entity.getDocument();
return createNewVersionAndConvert(document, bos);
}
/**
......@@ -190,33 +171,41 @@ public class UIDocumentService {
public DocumentRo getDocumentForResource(Long resourceId, int version) {
DBResource resource = resourceDao.find(resourceId);
DBDocument document = resource.getDocument();
DBDocumentVersion documentVersion = null;
DBDocumentVersion currentVersion = null;
for (DBDocumentVersion dv : document.getDocumentVersions()) {
if (dv.getVersion() == version) {
documentVersion = dv;
}
if (dv.getVersion() == document.getCurrentVersion()) {
currentVersion = dv;
}
}
documentVersion = documentVersion == null ? currentVersion : documentVersion;
if (documentVersion == null && !document.getDocumentVersions().isEmpty()) {
documentVersion = document.getDocumentVersions().get(document.getDocumentVersions().size() - 1);
}
return convert(document, documentVersion);
return convertWithVersion(document, version);
}
@Transactional
public DocumentRo getDocumentForSubResource(Long subresourceId, Long resourceId, int version) {
DBSubresource subresource = subresourceDao.find(subresourceId);
DBDocument document = subresource.getDocument();
DBDocumentVersion documentVersion = null;
DBDocumentVersion currentVersion = null;
return convertWithVersion(document, version);
}
/**
* return Create new Document version and convert DBDocument to DocumentRo
*
* @param document to convert to DocumentRo
* @param baos to write document content
* @return DocumentRo
*/
private DocumentRo createNewVersionAndConvert(DBDocument document, ByteArrayOutputStream baos) {
// get max version
int version = document.getDocumentVersions().stream().mapToInt(dv -> dv.getVersion())
.max().orElse(0);
DBDocumentVersion documentVersion = new DBDocumentVersion();
documentVersion.setVersion(version + 1);
documentVersion.setDocument(document);
documentVersion.setContent(baos.toByteArray());
document.getDocumentVersions().add(documentVersion);
document.setCurrentVersion(documentVersion.getVersion());
return convert(document, documentVersion);
}
public DocumentRo convertWithVersion(DBDocument document, int version) {
DBDocumentVersion currentVersion = null;
DBDocumentVersion documentVersion = null;
for (DBDocumentVersion dv : document.getDocumentVersions()) {
if (dv.getVersion() == version) {
documentVersion = dv;
......@@ -234,6 +223,7 @@ public class UIDocumentService {
public DocumentRo convert(DBDocument document, DBDocumentVersion version) {
DocumentRo documentRo = new DocumentRo();
// set list of versions
document.getDocumentVersions().forEach(dv ->
documentRo.getAllVersions().add(dv.getVersion()));
......
package eu.europa.ec.edelivery.smp.config.init;
import eu.europa.ec.edelivery.smp.config.SMPDatabaseConfig;
import eu.europa.ec.edelivery.smp.data.dao.AbstractJunit5BaseDao;
import eu.europa.ec.edelivery.smp.data.dao.ExtensionDao;
import eu.europa.ec.edelivery.smp.services.AbstractServiceTest;
import eu.europa.ec.smp.spi.OasisSMPExtension;
import eu.europa.ec.smp.spi.def.OasisSMPServiceGroup10;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional;
import static org.junit.jupiter.api.Assertions.*;
@ContextConfiguration( classes = {SMPExtensionInitializerTest.OasisSMPExtensionConfig.class}
)
public class SMPExtensionInitializerTest extends AbstractJunit5BaseDao {
@Configuration
@ComponentScan({"eu.europa.ec.smp.spi"})
public static class OasisSMPExtensionConfig {
}
@Autowired
SMPExtensionInitializer testInstance;
@Autowired
ExtensionDao extensionDao;
@Test
@Transactional
public void testValidateExtensionData() {
int extensionCount = extensionDao.getAllExtensions().size();
testInstance.validateExtensionData();
// added OasisSMP extension
assertEquals(extensionCount + 1, extensionDao.getAllExtensions().size());
}
}
package eu.europa.ec.edelivery.smp.config.init;
import eu.europa.ec.edelivery.security.utils.SecurityUtils;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyStore;
import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.*;
import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.TRUSTSTORE_FILENAME;
import static org.junit.jupiter.api.Assertions.*;
public class SMPKeystoreConfBuilderTest {
@Test
public void testBuild(){
File outputFolder = Paths.get("target").toFile();
SecurityUtils.Secret secret = SecurityUtils.generatePrivateSymmetricKey(true);
SMPConfigurationInitializer initPropertyService = Mockito.mock(SMPConfigurationInitializer.class);
KeyStore keystore = SMPKeystoreConfBuilder.create()
.propertySecurityToken(TRUSTSTORE_PASSWORD)
.propertyTruststoreDecToken(TRUSTSTORE_PASSWORD_DECRYPTED)
.propertyType(TRUSTSTORE_TYPE)
.propertyFilename(TRUSTSTORE_FILENAME)
.outputFolder(outputFolder)
.testMode(true)
.secret(secret)
.initPropertyService(initPropertyService)
.build();
assertNotNull(keystore);
}
}
package eu.europa.ec.edelivery.smp.data.dao;
import org.junit.Ignore;
/**
* Purpose of class is to test all resource methods with database.
*
* @author Joze Rihtarsic
* @since 4.1
*/
@Ignore
public class ServiceGroupDaoMetadataIntegrationTest extends AbstractResourceDaoTest {
/*
@Test
@Transactional
public void persistNewServiceGroupWithMetadata() {
// given
DBDomain d= domainDao.getDomainByCode(TEST_DOMAIN_CODE_1).get();
DBResource sg = new DBResource();
sg.setIdentifierValue(TEST_SG_ID_1);
sg.setIdentifierScheme(TEST_SG_SCHEMA_1);
sg.addDomain(d);
DBSubresource md = TestDBUtils.createDBSubresource(TEST_DOC_ID_1, TEST_DOC_SCHEMA_1);
sg.getResourceDomains().get(0).addServiceMetadata(md);
// when
testInstance.persistFlushDetach(sg);
// then
DBResource res = testInstance.findServiceGroup(TEST_SG_ID_1, TEST_SG_SCHEMA_1 ).get();
assertTrue(sg!=res); // test different object instance
assertNotNull(res.getId());
assertEquals(TEST_SG_ID_1, res.getIdentifierValue()); // test equal method - same entity
assertEquals(TEST_SG_SCHEMA_1, res.getIdentifierScheme()); // test equal method - same entity
assertEquals(1, res.getResourceDomains().size()); // domain must be loaded
assertEquals(d.getDomainCode(), res.getResourceDomains().get(0).getDomain().getDomainCode()); // test loaded Domain
}
@Test
@Transactional
public void addMetadataToServiceGroup() {
// given
DBResource sg = createAndSaveNewServiceGroup();
DBResource res = testInstance.findServiceGroup(sg.getIdentifierValue(), sg.getIdentifierScheme()).get();
DBSubresource md = TestDBUtils.createDBSubresource(TEST_DOC_ID_1, TEST_DOC_SCHEMA_1);
//when
res.getResourceDomains().get(0).addServiceMetadata(md);
assertNotNull(md.getXmlContent());
update(res);
testInstance.clearPersistenceContext();
// then
DBResource res2 = testInstance.findServiceGroup(sg.getIdentifierValue(), sg.getIdentifierScheme()).get();
assertNotNull(res2);
assertEquals(1, res2.getResourceDomains().get(0).getSubresourcesList().size());
assertTrue(Arrays.equals(md.getXmlContent(), res2.getResourceDomains().get(0).getSubresourcesList().get(0).getXmlContent()));
}
@Test
@Transactional
public void updateServiceMetadataXML() {
// given
DBResource sg = createAndSaveNewServiceGroupWithMetadata();
DBResource res = testInstance.findServiceGroup(sg.getIdentifierValue(), sg.getIdentifierScheme()).get();
DBSubresource md = res.getResourceDomains().get(0).getSubresource(0);
byte[] str = TestDBUtils.generateDocumentSample(sg.getIdentifierValue(),sg.getIdentifierScheme(),
md.getDocumentIdentifier(),md.getDocumentIdentifierScheme(),UUID.randomUUID().toString());
assertNotEquals (str, md.getXmlContent());
//when
res.getResourceDomains().get(0).getSubresource(0).setXmlContent(str);
update(res);
testInstance.clearPersistenceContext();
// then
DBResource res2 = testInstance.findServiceGroup(sg.getIdentifierValue(), sg.getIdentifierScheme()).get();
assertNotNull(res2);
assertEquals(1, res2.getResourceDomains().get(0).getSubresourcesList().size());
assertTrue(Arrays.equals(str, res2.getResourceDomains().get(0).getSubresourcesList().get(0).getXmlContent()));
}
@Test
@Transactional
public void removeServiceMetadata() {
// given
DBResource sg = createAndSaveNewServiceGroupWithMetadata();
DBResource res = testInstance.findServiceGroup(sg.getIdentifierValue(), sg.getIdentifierScheme()).get();
assertEquals(1, res.getResourceDomains().get(0).getSubresourcesList().size());
DBSubresource dsmd = res.getResourceDomains().get(0).getSubresourcesList().get(0);
// when
res.getResourceDomains().get(0).removeServiceMetadata(dsmd);
testInstance.update(res);
testInstance.clearPersistenceContext();
DBResource res2 = testInstance.findServiceGroup(sg.getIdentifierValue(), sg.getIdentifierScheme()).get();
// then
assertEquals(0, res.getResourceDomains().get(0).getSubresourcesList().size());
}
@Test
public void removeDBServiceGroupWithServiceMetadata() {
// given
DBResource sg = createAndSaveNewServiceGroupWithMetadata();
Optional<DBResource> resOpt1 = testInstance.findServiceGroup(sg.getIdentifierValue(), sg.getIdentifierScheme());
assertTrue(resOpt1.isPresent());
// when
testInstance.removeServiceGroup(resOpt1.get());
testInstance.clearPersistenceContext();
// then
Optional<DBResource> resOptDS = testInstance.findServiceGroup(sg.getIdentifierValue(), sg.getIdentifierScheme());
assertFalse(resOptDS.isPresent());
}
*/
}
package eu.europa.ec.edelivery.smp.data.dao;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.annotation.Autowired;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Purpose of class is to test all resource methods with database.
*
* @author Joze Rihtarsic
* @since 4.1
*/
@Ignore
public class ServiceMetadataDaoIntegrationTest extends AbstractBaseDao {
@Autowired
SubresourceDao testInstance;
@Autowired
DomainDao domainDao;
@Autowired
UserDao userDao;
@Autowired
ResourceDao serviceGroupDao;
@Rule
public ExpectedException expectedEx = ExpectedException.none();
@Test
public void mockTest(){
}
/*
@Before
@Transactional
public void prepareDatabase() {
DBDomain testDomain01 =TestDBUtils.createDBDomain(TestConstants.TEST_DOMAIN_CODE_1);
DBDomain testDomain02 =TestDBUtils.createDBDomain(TestConstants.TEST_DOMAIN_CODE_2);
domainDao.persistFlushDetach(testDomain01);
domainDao.persistFlushDetach(testDomain02);
DBUser u1 = TestDBUtils.createDBUserByUsername(TestConstants.USERNAME_1);
DBUser u2 = TestDBUtils.createDBUserByCertificate(TestConstants.USER_CERT_2);
userDao.persistFlushDetach(u1);
userDao.persistFlushDetach(u2);
// create service group with two documents in one domains
DBResource sg1d1 = TestDBUtils.createDBServiceGroup(TEST_SG_ID_1, TEST_SG_SCHEMA_1);
DBSubresource sg1md1 = TestDBUtils.createDBSubresource(TEST_SG_ID_1, TEST_SG_SCHEMA_1,
TEST_DOC_ID_1, TEST_DOC_SCHEMA_1);
DBSubresource sg1md2 = TestDBUtils.createDBSubresource(TEST_SG_ID_1, TEST_SG_SCHEMA_1,
TEST_DOC_ID_2, TEST_DOC_SCHEMA_2);
sg1d1.addDomain(testDomain01);
sg1d1.getServiceGroupDomains().get(0).addServiceMetadata(sg1md1);
sg1d1.getServiceGroupDomains().get(0).addServiceMetadata(sg1md2);
sg1d1.getUsers().add(u1);
sg1d1.getUsers().add(u2);
serviceGroupDao.update(sg1d1);
// create service group one document in two domains
DBResource sg2 = TestDBUtils.createDBServiceGroup(TEST_SG_ID_2, TEST_SG_SCHEMA_2);
DBSubresource sg2md1 = TestDBUtils.createDBSubresource(TEST_SG_ID_2, TEST_SG_SCHEMA_2,
TEST_DOC_ID_1, TEST_DOC_SCHEMA_1);
DBSubresource sg2md2 = TestDBUtils.createDBSubresource(TEST_SG_ID_2, TEST_SG_SCHEMA_2,
TEST_DOC_ID_2, TEST_DOC_SCHEMA_2);
sg2.addDomain(testDomain01);
sg2.addDomain(testDomain02);
sg2.getServiceGroupDomains().get(0).addServiceMetadata(sg2md1);
sg2.getServiceGroupDomains().get(1).addServiceMetadata(sg2md2);
sg2.getUsers().add(u1);
sg2.getUsers().add(u2);
serviceGroupDao.update(sg2);
}
@Test
@Transactional
public void testFindServiceMetadata() {
// given
// when
Optional<DBSubresource> osmd1 = testInstance.findServiceMetadata(TEST_SG_ID_1, TEST_SG_SCHEMA_1,
TEST_DOC_ID_1, TEST_DOC_SCHEMA_1);
Optional<DBSubresource> osmd2 = testInstance.findServiceMetadata(TEST_SG_ID_2, TEST_SG_SCHEMA_2,
TEST_DOC_ID_1, TEST_DOC_SCHEMA_1);
// test
assertTrue(osmd1.isPresent());
assertTrue(osmd2.isPresent());
}
@Test
@Transactional
public void testFindServiceMetadataList() {
// given
// when
List<DBSubresource> lst1 = testInstance.getAllMetadataForServiceGroup(TEST_SG_ID_1, TEST_SG_SCHEMA_1);
List<DBSubresource> lst2 = testInstance.getAllMetadataForServiceGroup(TEST_SG_ID_2, TEST_SG_SCHEMA_2);
// test
assertEquals(2, lst1.size());
assertEquals(2, lst2.size());
}*/
}
......@@ -21,9 +21,8 @@ import static org.junit.Assert.assertNotNull;
public class SMPAuthorityDeserializerTest {
@Test
@Ignore
public void deserialize() throws IOException {
String value = "{\"username\":\"smp\",\"password\":null,\"emailAddress\":null,\"authorities\":[\"ROLE_USER\"],\"active\":true,\"role\":\"ROLE_USER\",\"certificate\":null,\"statusPassword\":0,\"passwordExpired\":true}";
String value = "{\"status\":0,\"index\":0,\"actionMessage\":null,\"userId\":\"hsAkhiqJp1o89VZ4iBtmLnEM2vkb5FJTt0vWEUIxOw\",\"username\":\"user\",\"active\":true,\"role\":\"USER\",\"emailAddress\":\"user@mail-example.local\",\"fullName\":null,\"smpTheme\":null,\"smpLocale\":null,\"casAuthenticated\":false,\"casUserDataUrl\":null,\"passwordExpireOn\":null,\"sequentialLoginFailureCount\":0,\"lastFailedLoginAttempt\":null,\"suspendedUtil\":null,\"passwordUpdatedOn\":null,\"authorities\":[\"ROLE_USER\"],\"statusPassword\":0,\"passwordExpired\":true,\"showPasswordExpirationWarning\":false,\"forceChangeExpiredPassword\":false}";
ObjectMapper mapper = new ObjectMapper();
UserRO userRO = mapper.readValue(value, UserRO.class);
......@@ -31,6 +30,5 @@ public class SMPAuthorityDeserializerTest {
assertNotNull(userRO.getAuthorities());
assertEquals(1, userRO.getAuthorities().size());
assertEquals(SMPAuthority.S_AUTHORITY_USER.getAuthority(), userRO.getAuthorities().toArray(new SMPAuthority[]{})[0].getAuthority());
}
}
......@@ -55,7 +55,6 @@ import static org.mockito.Mockito.verify;
SMLIntegrationService.class})
public class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest {
@Autowired
IdentifierService identifierService;
@Autowired
......
......@@ -13,7 +13,7 @@ import org.springframework.test.context.ContextConfiguration;
import static org.junit.Assert.assertEquals;
@Ignore
@ContextConfiguration(classes = UIAlertService.class)
public class UIAlertServiceIntegrationTest extends AbstractServiceIntegrationTest {
......
......@@ -105,4 +105,42 @@ public class UIDocumentServiceTest extends AbstractServiceIntegrationTest {
MatcherAssert.assertThat(result.getMessage(), CoreMatchers.containsString("Invalid request [ResourceValidation]"));
}
@Test
public void testGetDocumentForResource(){
DBResource resource = testUtilsDao.getResourceD1G1RD1();
DocumentRo testDoc = testInstance.getDocumentForResource(resource.getId(), 1);
assertNotNull(testDoc.getPayload());
}
@Test
public void testGetDocumentForSubResource(){
DBSubresource subresource = testUtilsDao.getSubresourceD1G1RD1_S1();
DocumentRo testDoc = testInstance.getDocumentForSubResource(subresource.getId(), subresource.getResource().getId(), 1);
assertNotNull(testDoc.getPayload());
}
@Test
public void testSaveDocumentForResource(){
DBResource resource = testUtilsDao.getResourceD1G1RD1();
DocumentRo testDoc = testInstance.generateDocumentForResource(resource.getId(), null);
assertNotNull(testDoc.getPayload());
//when
DocumentRo result = testInstance.saveDocumentForResource(resource.getId(), testDoc);
// then
assertNotNull(result);
}
@Test
public void testSaveSubresourceDocumentForResource(){
DBSubresource subresource = testUtilsDao.getSubresourceD1G1RD1_S1();
DocumentRo testDoc = testInstance.generateDocumentForSubresource(subresource.getId(),
subresource.getResource().getId(),
null);
assertNotNull(testDoc.getPayload());
//when
DocumentRo result = testInstance.saveSubresourceDocumentForResource(subresource.getId(), subresource.getResource().getId(), testDoc);
// then
assertNotNull(result);
}
}
......@@ -24,7 +24,6 @@ import static org.junit.Assert.*;
* @author Joze Rihtarsic
* @since 4.1
*/
@Ignore
@ContextConfiguration(classes= UIDomainService.class)
public class UIDomainServiceIntegrationTest extends AbstractServiceIntegrationTest {
@Rule
......@@ -42,10 +41,7 @@ public class UIDomainServiceIntegrationTest extends AbstractServiceIntegrationTe
@Test
public void testGetTableListEmpty(){
// given
//when
// given when
ServiceResult<DomainRO> res = testInstance.getTableList(-1,-1,null, null, null);
// then
assertNotNull(res);
......
......@@ -24,11 +24,10 @@ import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.SMP_CLUSTE
import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.SMP_PROPERTY_REFRESH_CRON;
import static org.junit.Assert.*;
@Ignore
@ContextConfiguration(classes = {UIPropertyService.class})
public class UIPropertyServiceIntegrationTest extends AbstractServiceIntegrationTest {
@Autowired
protected UIPropertyService testInstance;
@Autowired
......@@ -130,7 +129,7 @@ public class UIPropertyServiceIntegrationTest extends AbstractServiceIntegration
assertEquals(propertyName, result.getProperty());
assertEquals(propertyValue, result.getValue());
assertFalse(result.isPropertyValid());
MatcherAssert.assertThat(result.getErrorMessage(), CoreMatchers.containsString("Invalid integer: [" + propertyValue + "]. Error:NumberFormatException: For input string: \"" + propertyValue + "\"!"));
MatcherAssert.assertThat(result.getErrorMessage(), CoreMatchers.containsString("Invalid integer: [" + propertyValue + "]. Error:NumberFormatException"));
}
@Test
......
DELETE FROM SMP_ALERT;
DELETE FROM SMP_ALERT_AUD;
DELETE FROM SMP_ALERT_PROPERTY;
DELETE FROM SMP_ALERT_PROPERTY_AUD;
DELETE FROM SMP_ALERT;
DELETE FROM SMP_ALERT_AUD;
DELETE FROM SMP_CERTIFICATE;
DELETE FROM SMP_CERTIFICATE_AUD;
DELETE FROM SMP_CONFIGURATION;
......
......@@ -5,25 +5,21 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import eu.europa.ec.edelivery.smp.data.ui.CertificateRO;
import eu.europa.ec.edelivery.smp.data.ui.ServiceResult;
import eu.europa.ec.edelivery.smp.data.ui.UserRO;
import eu.europa.ec.edelivery.smp.services.ui.UITruststoreService;
import eu.europa.ec.edelivery.smp.test.SmpTestWebAppConfig;
import eu.europa.ec.edelivery.smp.test.testutils.X509CertificateTestUtils;
import eu.europa.ec.edelivery.smp.ui.AbstractControllerTest;
import eu.europa.ec.edelivery.smp.ui.external.UserResourceIntegrationTest;
import org.apache.commons.io.IOUtils;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.web.context.WebApplicationContext;
......@@ -37,21 +33,12 @@ import static eu.europa.ec.edelivery.smp.ui.ResourceConstants.CONTEXT_PATH_INTER
import static eu.europa.ec.edelivery.smp.ui.ResourceConstants.CONTEXT_PATH_PUBLIC_TRUSTSTORE;
import static org.junit.Assert.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@DirtiesContext
@WebAppConfiguration
@ContextConfiguration(classes = {SmpTestWebAppConfig.class, UITruststoreService.class})
@Sql(scripts = {
"classpath:/cleanup-database.sql",
"classpath:/webapp_integration_test_data.sql"},
executionPhase = BEFORE_TEST_METHOD)
@Ignore
public class TruststoreAdminResourceIntegrationTest{
public class TruststoreAdminResourceIntegrationTest extends AbstractControllerTest {
private static final String PATH_INTERNAL = CONTEXT_PATH_INTERNAL_TRUSTSTORE;
private static final String PATH_PUBLIC = CONTEXT_PATH_PUBLIC_TRUSTSTORE;
......@@ -63,10 +50,11 @@ public class TruststoreAdminResourceIntegrationTest{
private MockMvc mvc;
@Before
@BeforeEach
public void setup() throws IOException {
uiTruststoreService.refreshData();
X509CertificateTestUtils.reloadKeystores();
uiTruststoreService.refreshData();
mvc = initializeMockMvc(webAppContext);
}
......@@ -82,9 +70,9 @@ public class TruststoreAdminResourceIntegrationTest{
// given when
mvc.perform(post(PATH_PUBLIC + "/" + userRO.getUserId() + "/validate-certificate")
.session(session)
.with(csrf())
.content(buff))
.session(session)
.with(csrf())
.content(buff))
.andExpect(status().isOk())
.andExpect(content().string(CoreMatchers.containsString("Can not read the certificate!")));
}
......@@ -98,9 +86,9 @@ public class TruststoreAdminResourceIntegrationTest{
UserRO userRO = getLoggedUserData(mvc, session);
// given when
MvcResult result = mvc.perform(post(PATH_PUBLIC + "/" + userRO.getUserId() + "/validate-certificate")
.session(session)
.with(csrf())
.content(buff))
.session(session)
.with(csrf())
.content(buff))
.andExpect(status().isOk()).andReturn();
//then
......@@ -129,13 +117,13 @@ public class TruststoreAdminResourceIntegrationTest{
byte[] buff = certificate.getEncoded();
// given when
MvcResult result = mvc.perform(post(PATH_PUBLIC + "/" + userRO.getUserId() + "/validate-certificate")
.session(session)
.with(csrf())
.content(buff))
.session(session)
.with(csrf())
.content(buff))
.andExpect(status().isOk()).andReturn();
//them
ObjectMapper mapper =getObjectMapper();
ObjectMapper mapper = getObjectMapper();
CertificateRO res = mapper.readValue(result.getResponse().getContentAsString(), CertificateRO.class);
assertEquals("CN=common name,O=org,C=BE:0000000001234321", res.getCertificateId());
......@@ -147,9 +135,9 @@ public class TruststoreAdminResourceIntegrationTest{
// id and logged user not match
// given when
mvc.perform(post(PATH_PUBLIC + "/34556655/validate-certificate")
.with(getHttpBasicSMPAdminCredentials())
.with(csrf())
.content(buff))
.with(getHttpBasicSMPAdminCredentials())
.with(csrf())
.content(buff))
.andExpect(status().isUnauthorized()).andReturn();
}
......@@ -162,14 +150,15 @@ public class TruststoreAdminResourceIntegrationTest{
UserRO userRO = getLoggedUserData(mvc, session);
int countStart = uiTruststoreService.getCertificateROEntriesList().size();
MvcResult result = mvc.perform(get(PATH_INTERNAL+ "/" + userRO.getUserId())
.session(session)
.with(csrf()))
MvcResult result = mvc.perform(get(PATH_INTERNAL + "/" + userRO.getUserId())
.session(session)
.with(csrf()))
.andExpect(status().isOk()).andReturn();
//then
ObjectMapper mapper = getObjectMapper();
List<CertificateRO> listCerts = mapper.readValue(result.getResponse().getContentAsString(), new TypeReference<List<CertificateRO>>(){});
List<CertificateRO> listCerts = mapper.readValue(result.getResponse().getContentAsString(), new TypeReference<List<CertificateRO>>() {
});
assertNotNull(listCerts);
assertEquals(countStart, listCerts.size());
......@@ -193,9 +182,9 @@ public class TruststoreAdminResourceIntegrationTest{
int countStart = uiTruststoreService.getNormalizedTrustedList().size();
MvcResult prepRes = mvc.perform(post(PATH_INTERNAL + "/" + userRO.getUserId() + "/upload-certificate")
.session(session)
.with(csrf())
.content(buff))
.session(session)
.with(csrf())
.content(buff))
.andExpect(status().isOk()).andReturn();
// given when
......@@ -207,17 +196,12 @@ public class TruststoreAdminResourceIntegrationTest{
// then
MvcResult result = mvc.perform(delete(PATH_INTERNAL + "/" + userRO.getUserId() + "/delete/" + res.getAlias())
.session(session)
.with(csrf())
.content(buff))
.session(session)
.with(csrf())
.content(buff))
.andExpect(status().isOk()).andReturn();
uiTruststoreService.refreshData();
assertEquals(countStart, uiTruststoreService.getNormalizedTrustedList().size());
}
protected ObjectMapper getObjectMapper(){
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
return mapper;
}
}
DELETE FROM SMP_ALERT;
DELETE FROM SMP_ALERT_AUD;
DELETE FROM SMP_ALERT_PROPERTY;
DELETE FROM SMP_ALERT_PROPERTY_AUD;
DELETE FROM SMP_ALERT;
DELETE FROM SMP_ALERT_AUD;
DELETE FROM SMP_CERTIFICATE;
DELETE FROM SMP_CERTIFICATE_AUD;
DELETE FROM SMP_CONFIGURATION;
......
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