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

Skip to content
Snippets Groups Projects
Commit 7e387688 authored by Mihai BOZ's avatar Mihai BOZ
Browse files

Merge branch 'development' into EDELIVERY-12323-Automate_new_SMP_UI_testcases-part_7

parents 7eb0fce7 56ff6cd2
No related branches found
No related tags found
No related merge requests found
Showing
with 61 additions and 42 deletions
package eu.europa.ec.edelivery.smp.data.ui;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
......@@ -12,6 +13,7 @@ public class DocumentRo {
String name;
Integer payloadVersion;
String payload;
OffsetDateTime payloadCreatedOn;
public String getDocumentId() {
return documentId;
......@@ -67,4 +69,12 @@ public class DocumentRo {
public void setPayload(String payload) {
this.payload = payload;
}
public OffsetDateTime getPayloadCreatedOn() {
return payloadCreatedOn;
}
public void setPayloadCreatedOn(OffsetDateTime payloadCreatedOn) {
this.payloadCreatedOn = payloadCreatedOn;
}
}
......@@ -70,13 +70,9 @@ public enum ErrorCode {
MAIL_SUBMISSION_ERROR (500,"SMP:550",ErrorBusinessCode.TECHNICAL, "Mail submission error: %s!"),
RESOURCE_DOCUMENT_MISSING(500,"SMP:180",ErrorBusinessCode.TECHNICAL, "Empty document for the resource: [id: '%s', sch.: '%s']!"),
RESOURCE_DOCUMENT_ERROR(500,"SMP:180",ErrorBusinessCode.TECHNICAL, "Error occurred while reading the resource document: [id: '%s', sch.: '%s']! Error [%s]"),
//
RESOURCE_DOCUMENT_ERROR(500,"SMP:181",ErrorBusinessCode.TECHNICAL, "Error occurred while reading the resource document: [id: '%s', sch.: '%s']! Error [%s]"),
SUBRESOURCE_DOCUMENT_MISSING(500,"SMP:182",ErrorBusinessCode.TECHNICAL, "Empty document for the subresource: [docId: '%s', docSch.: '%s'] of the resource [id: '%s', sch.: '%s']"),
SUBRESOURCE_DOCUMENT_ERROR(500,"SMP:183",ErrorBusinessCode.TECHNICAL, "Error occurred while reading the subresource document: : [docId: '%s', docSch.: '%s'] of the resource[id: '%s', sch: '%s']! Error [%s]"),
;
private final int httpCode;
......
......@@ -105,10 +105,15 @@ public class AbstractResourceHandler {
public RequestData buildRequestDataForSubResource(DBDomain domain, DBResource resource, DBSubresource subresource) {
byte[] content = resourceStorage.getDocumentContentForSubresource(subresource);
if (content==null || content.length == 0) {
throw new SMPRuntimeException(ErrorCode.SUBRESOURCE_DOCUMENT_MISSING,
subresource.getIdentifierValue(), subresource.getIdentifierScheme(),
resource.getIdentifierValue(), resource.getIdentifierScheme());
}
return new SpiRequestData(domain.getDomainCode(),
SPIUtils.toUrlIdentifier(resource),
SPIUtils.toUrlIdentifier(subresource),
new ByteArrayInputStream(content == null?new byte[]{}:content));
new ByteArrayInputStream(content));
}
public RequestData buildRequestDataForSubResource(DBDomain domain, DBResource resource, DBSubresource subresource, InputStream inputStream) {
......@@ -124,7 +129,7 @@ public class AbstractResourceHandler {
if (StringUtils.isNotBlank(responseData.getContentType())) {
resourceResponse.setContentType(responseData.getContentType());
}
responseData.getHttpHeaders().entrySet().stream()
responseData.getHttpHeaders().entrySet()
.forEach(entry -> resourceResponse.setHttpHeader(entry.getKey(), entry.getValue()));
} catch (ResourceException e) {
......
......@@ -78,32 +78,25 @@ public class UIDocumentService {
RequestData data = resourceHandlerService.buildRequestDataForResource(domainResourceDef.getDomain(),
resource, null);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ResponseData responseData = new SpiResponseData(bos);
try {
resourceHandler.generateResource(data, responseData, Collections.emptyList());
} catch (ResourceException e) {
throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, "StoreResourceValidation", ExceptionUtils.getRootCauseMessage(e));
}
String genDoc = new String(bos.toByteArray());
LOG.info("Generate document [{}]", genDoc);
DocumentRo result = new DocumentRo();
result.setPayload(genDoc);
return result;
return getDocumentRo(resourceHandler, data);
}
@Transactional
public DocumentRo generateDocumentForSubresource(Long subresourceId, Long resourceId, DocumentRo documentRo) {
LOG.info("Generate document");
DBResource parentEntity = resourceDao.find(resourceId);
DBSubresource enitity = subresourceDao.find(subresourceId);
DBSubresourceDef subresourceDef = enitity.getSubresourceDef();
DBSubresource entity = subresourceDao.find(subresourceId);
DBSubresourceDef subresourceDef = entity.getSubresourceDef();
ResourceHandlerSpi resourceHandler = resourceHandlerService.getSubresourceHandler(subresourceDef, subresourceDef.getResourceDef());
RequestData data = resourceHandlerService.buildRequestDataForSubResource(parentEntity.getDomainResourceDef().getDomain(),
parentEntity, enitity);
parentEntity, entity);
return getDocumentRo(resourceHandler, data);
}
private DocumentRo getDocumentRo(ResourceHandlerSpi resourceHandler, RequestData data) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ResponseData responseData = new SpiResponseData(bos);
try {
......@@ -111,7 +104,7 @@ public class UIDocumentService {
} catch (ResourceException e) {
throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, "StoreResourceValidation", ExceptionUtils.getRootCauseMessage(e));
}
String genDoc = new String(bos.toByteArray());
String genDoc = bos.toString();
LOG.info("Generate document [{}]", genDoc);
DocumentRo result = new DocumentRo();
result.setPayload(genDoc);
......@@ -163,9 +156,9 @@ public class UIDocumentService {
* return version, if version does not exists return current version. if current version does not exists
* return last version
*
* @param resourceId
* @param version
* @return
* @param resourceId resource id of the document
* @param version version of the payload for the document
* @return DocumentRo with payload and version
*/
@Transactional
public DocumentRo getDocumentForResource(Long resourceId, int version) {
......@@ -198,6 +191,9 @@ public class UIDocumentService {
documentVersion.setVersion(version + 1);
documentVersion.setDocument(document);
documentVersion.setContent(baos.toByteArray());
// to get the current persist time
documentVersion.prePersist();
document.getDocumentVersions().add(documentVersion);
document.setCurrentVersion(documentVersion.getVersion());
return convert(document, documentVersion);
......@@ -231,6 +227,7 @@ public class UIDocumentService {
documentRo.setName(document.getName());
documentRo.setCurrentResourceVersion(document.getCurrentVersion());
if (version != null) {
documentRo.setPayloadCreatedOn(version.getCreatedOn());
documentRo.setPayloadVersion(version.getVersion());
documentRo.setPayload(new String(version.getContent()));
}
......
......@@ -29,7 +29,7 @@ public class DocumentDaoTest extends AbstractBaseDao {
assertNotNull(document.getId());
assertEquals(2, document.getDocumentVersions().size());
assertEquals(1, document.getCurrentVersion());
assertEquals(2, document.getCurrentVersion());
}
......@@ -40,7 +40,7 @@ public class DocumentDaoTest extends AbstractBaseDao {
assertTrue(result.isPresent());
assertEquals(testUtilsDao.getDocumentD1G1RD1(), result.get());
// the default setup createResources sets two versions (0 and 1 ) with current version 1
assertEquals(1, result.get().getCurrentVersion());
assertEquals(2, result.get().getCurrentVersion());
}
......@@ -58,7 +58,7 @@ public class DocumentDaoTest extends AbstractBaseDao {
assertTrue(result.isPresent());
// the default setup createResources sets two versions (0 and 1 ) with current version 1
assertEquals(1, result.get().getVersion());
assertEquals(2, result.get().getVersion());
assertEquals(testUtilsDao.getDocumentD1G1RD1().getDocumentVersions().get(1), result.get());
}
......@@ -76,8 +76,8 @@ public class DocumentDaoTest extends AbstractBaseDao {
Optional<DBDocumentVersion> result = testInstance.getCurrentDocumentVersionForSubresource(testUtilsDao.getSubresourceD1G1RD1_S1());
assertTrue(result.isPresent());
// the default setup createResources sets two versions (0 and 1 ) with current version 1
assertEquals(1, result.get().getVersion());
// the default setup createResources sets two versions (1 and 2 ) with current version 2
assertEquals(2, result.get().getVersion());
assertEquals(testUtilsDao.getDocumentD1G1RD1_S1().getDocumentVersions().get(1), result.get());
}
}
......@@ -63,16 +63,18 @@ public class ResourceDaoTest extends AbstractBaseDao {
Assert.assertTrue(optResult.isPresent());
Assert.assertNotNull(optResult.get().getDocument());
Assert.assertNotNull(optResult.get().getDocument().getId());
Assert.assertEquals(0, optResult.get().getDocument().getCurrentVersion());
Assert.assertEquals(1, optResult.get().getDocument().getCurrentVersion());
Assert.assertEquals(1, optResult.get().getDocument().getDocumentVersions().size());
Assert.assertNotNull(optResult.get().getDocument().getDocumentVersions().get(0).getId());
Assert.assertEquals(0, optResult.get().getDocument().getDocumentVersions().get(0).getVersion());
Assert.assertEquals(1, optResult.get().getDocument().getDocumentVersions().get(0).getVersion());
}
@Test
@Transactional
public void persistNewVersionToResourceWithDocument() {
Optional<DBResource> optResource = testInstance.getResource(TEST_SG_ID_1, TEST_SG_SCHEMA_1, testUtilsDao.getResourceDefSmp(), testUtilsDao.getD1());
Optional<DBResource> optResource = testInstance.getResource(TEST_SG_ID_1, TEST_SG_SCHEMA_1,
testUtilsDao.getResourceDefSmp(), testUtilsDao.getD1());
Assert.assertTrue(optResource.isPresent());
DBResource resource = testInstance.find(optResource.get().getId());
int docCount = resource.getDocument().getDocumentVersions().size();
......
......@@ -25,6 +25,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.Optional;
import static eu.europa.ec.edelivery.smp.testutil.TestConstants.*;
import static eu.europa.ec.edelivery.smp.testutil.TestDBUtils.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
......@@ -248,9 +250,15 @@ public class TestUtilsDao {
@Transactional
public void deactivateUser(String username) {
DBUser user = userDao.findUserByUsername(username).get();
Optional<DBUser> userOpt = userDao.findUserByUsername(username);
if (!userOpt.isPresent()) {
LOG.warn("User [{}] not found and cannot be deactivated!", username);
return;
}
DBUser user = userOpt.get();
user.setActive(false);
persistFlushDetach(user);
}
......@@ -490,7 +498,7 @@ public class TestUtilsDao {
assertNotNull(document.getDocumentVersions().get(i).getId());
}
// current version is the last version
assertEquals(versions-1, document.getCurrentVersion());
assertEquals(versions, document.getCurrentVersion());
return document;
}
......@@ -615,9 +623,6 @@ public class TestUtilsDao {
return memEManager.find(clazz, id);
}
public void clear() {
memEManager.clear();
}
......
......@@ -3,9 +3,11 @@ package eu.europa.ec.edelivery.smp.ui.internal;
import eu.europa.ec.edelivery.smp.data.ui.AlertRO;
import eu.europa.ec.edelivery.smp.data.ui.ServiceResult;
import eu.europa.ec.edelivery.smp.data.ui.auth.SMPAuthority;
import eu.europa.ec.edelivery.smp.logging.SMPLogger;
import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory;
import eu.europa.ec.edelivery.smp.services.ui.UIAlertService;
import org.springframework.security.access.annotation.Secured;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -31,6 +33,7 @@ public class AlertController {
}
@GetMapping(produces = {MimeTypeUtils.APPLICATION_JSON_VALUE})
@Secured({SMPAuthority.S_AUTHORITY_TOKEN_SYSTEM_ADMIN})
public ServiceResult<AlertRO> getAlertList(
@RequestParam(value = PARAM_PAGINATION_PAGE, defaultValue = "0") int page,
@RequestParam(value = PARAM_PAGINATION_PAGE_SIZE, defaultValue = "10") int pageSize,
......
......@@ -36,7 +36,8 @@ public class PropertyController {
}
@GetMapping(produces = {MimeTypeUtils.APPLICATION_JSON_VALUE})
public ServiceResult<PropertyRO> gePropertyList(
@Secured({SMPAuthority.S_AUTHORITY_TOKEN_SYSTEM_ADMIN})
public ServiceResult<PropertyRO> getPropertyList(
@RequestParam(value = PARAM_PAGINATION_PAGE, defaultValue = "0") int page,
@RequestParam(value = PARAM_PAGINATION_PAGE_SIZE, defaultValue = "10") int pageSize,
@RequestParam(value = PARAM_PAGINATION_ORDER_BY, required = false) String orderBy,
......
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