Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALFREDAPI-518 fix test #160

Merged
merged 3 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 46 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
name: 'Continuous Integration'
on:
push:
branches:
- 'master*'
- 'release*'
pull_request:
workflow_dispatch:
env:
ALFRESCO_NEXUS_USERNAME: ${{ secrets.ALFRESCO_NEXUS_USERNAME }}
ALFRESCO_NEXUS_PASSWORD: ${{ secrets.ALFRESCO_NEXUS_PASSWORD }}
jobs:
BuildAndPublish:
test:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
- name: Build interface
uses: gradle/gradle-build-action@v2.3.0
with:
arguments: :apix-interface:build :apix-interface:javadoc
- name: Unit test REST API
uses: gradle/gradle-build-action@v2.3.0
with:
arguments: --info :apix-rest-v1:test
- name: Upload test reports
if: always()
uses: actions/upload-artifact@v3
with:
name: test-result
path: /home/runner/work/**/build/reports
retention-days: 2
integration-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
alfresco_version: [ 62, 70, 71, 72, 73 ]
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
Expand All @@ -26,25 +51,8 @@ jobs:
registry: private.docker.xenit.eu
username: ${{ secrets.CLOUDSMITH_USER }}
password: ${{ secrets.CLOUDSMITH_APIKEY }}
- name: Build interface # Execute before integration testing to catch errors early
uses: gradle/gradle-build-action@v2.3.0
env:
XENIT_ARTIFACTORY_USERNAME: ${{ secrets.XENIT_ARTIFACTORY_USERNAME }}
XENIT_ARTIFACTORY_PASSWORD: ${{ secrets.XENIT_ARTIFACTORY_PASSWORD }}
with:
arguments: :apix-interface:build :apix-interface:javadoc
- name: Unit test REST API
uses: gradle/gradle-build-action@v2.3.0
env:
XENIT_ARTIFACTORY_USERNAME: ${{ secrets.XENIT_ARTIFACTORY_USERNAME }}
XENIT_ARTIFACTORY_PASSWORD: ${{ secrets.XENIT_ARTIFACTORY_PASSWORD }}
with:
arguments: --info :apix-rest-v1:test
- name: Build and test
- name: Integration test and apix impl test
uses: gradle/gradle-build-action@v2.3.0
env:
XENIT_ARTIFACTORY_USERNAME: ${{ secrets.XENIT_ARTIFACTORY_USERNAME }}
XENIT_ARTIFACTORY_PASSWORD: ${{ secrets.XENIT_ARTIFACTORY_PASSWORD }}
with:
arguments: >-
--info
Expand All @@ -54,15 +62,24 @@ jobs:
if: always()
uses: actions/upload-artifact@v3
with:
name: test-result
name: test-result-${{ matrix.alfresco_version }}
path: /home/runner/work/**/build/reports
retention-days: 2
publish:
needs: [ test, integration-test ]
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/heads/release') }}
steps:
- name: Check out
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
- name: Publish
if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/heads/release') }}"
uses: gradle/gradle-build-action@v2.3.0
env:
XENIT_ARTIFACTORY_USERNAME: ${{ secrets.XENIT_ARTIFACTORY_USERNAME }}
XENIT_ARTIFACTORY_PASSWORD: ${{ secrets.XENIT_ARTIFACTORY_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.MAVEN_CENTRAL_GPG_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.MAVEN_CENTRAL_GPG_PASSWORD }}
ORG_GRADLE_PROJECT_sonatype_username: ${{ secrets.SONATYPE_S01_USERNAME }}
Expand All @@ -71,4 +88,4 @@ jobs:
arguments: >-
--info -PsigningKeyId=DF8285F0
:apix-interface:publish
:alfresco:${{ matrix.alfresco_version }}:publish
:alfresco:publish
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ protected Comment toComment(org.alfresco.service.cmr.repository.NodeRef document
Comment response = new Comment();
response.setId(apixCommentNodeRef);
response.setContent(content);
List<String> property = commentMetadata.properties.get(new QName(ContentModel.PROP_TITLE.toString()));
List<String> property = commentMetadata.getProperties().get(new QName(ContentModel.PROP_TITLE.toString()));
if (property != null && !property.isEmpty()) {
response.setTitle(property.get(0));
}
property = commentMetadata.properties.get(new QName(ContentModel.PROP_CREATED.toString()));
property = commentMetadata.getProperties().get(new QName(ContentModel.PROP_CREATED.toString()));
if (property != null && !property.isEmpty()) {
response.setCreatedAt(property.get(0));
}
property = commentMetadata.properties.get(new QName(ContentModel.PROP_CREATOR.toString()));
property = commentMetadata.getProperties().get(new QName(ContentModel.PROP_CREATOR.toString()));
if (property != null && !property.isEmpty()) {
response.setCreatedBy(property.get(0));
}
property = commentMetadata.properties.get(new QName(ContentModel.PROP_MODIFIED.toString()));
property = commentMetadata.getProperties().get(new QName(ContentModel.PROP_MODIFIED.toString()));
if (property != null && !property.isEmpty()) {
response.setModifiedAt(property.get(0));
}
property = commentMetadata.properties.get(new QName(ContentModel.PROP_MODIFIER.toString()));
property = commentMetadata.getProperties().get(new QName(ContentModel.PROP_MODIFIER.toString()));
if (property != null && !property.isEmpty()) {
response.setModifiedBy(property.get(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public Configurations getConfigurationFiles(String searchDirectory, String nameF
ContentInputStream configStream = contentService.getContent(configurationFile.getNodeRef());
if (configStream != null) {
String mimetype = configStream.getMimetype();
String name = configurationFile.getMetadata().properties.get(QNAME_NAME).get(0);
String name = configurationFile.getMetadata().getProperties().get(QNAME_NAME).get(0);
logger.debug("Mimetype is {}; filename is {}", mimetype, name);
Object parsedContent = null;
if (mimetype.equals("text/x-yaml") || name.endsWith(".yaml") || name.endsWith(".yml")) {
Expand Down Expand Up @@ -144,7 +144,7 @@ private List<ConfigurationFile> getChildrenRecursive(NodeRef parent, Configurati
for (ChildParentAssociation childParentAssociation : childParentAssociations) {
NodeRef child = childParentAssociation.getTarget();
NodeMetadata childMetadata = nodeService.getMetadata(child);
if (childMetadata.type.getValue().equals(QNAME_FOLDER)) {
if (childMetadata.getType().getValue().equals(QNAME_FOLDER)) {
files.addAll(getChildrenRecursive(child, filter));
} else if (filter.isAccepted(childMetadata)) {
files.add(new ConfigurationFile(child, childMetadata));
Expand All @@ -171,7 +171,7 @@ class NameFilter implements ConfigurationServiceImpl.Filter {

@Override
public boolean isAccepted(NodeMetadata metadata) {
String name = metadata.properties.get(QNAME_NAME).get(0);
String name = metadata.getProperties().get(QNAME_NAME).get(0);
logger.debug("Checking if {} matches {}", name, filter);
return filter.matcher(name).find();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@Component("eu.xenit.apix.dictionary.IDictionaryService")
public class DictionaryService implements IDictionaryService {

private final static Logger logger = LoggerFactory.getLogger(DictionaryService.class);
private static final Logger logger = LoggerFactory.getLogger(DictionaryService.class);
@Autowired
private ApixToAlfrescoConversion c;
@Autowired
Expand All @@ -55,8 +55,6 @@ public class DictionaryService implements IDictionaryService {
@Autowired
private NamespaceService namespaceService;

public DictionaryService() {
}

public Namespaces getNamespaces() {
Map<String, Namespace> ret = new HashMap<>();
Expand All @@ -65,7 +63,7 @@ public Namespaces getNamespaces() {
if (s == null || s.length() == 0) {
continue;
}
ret.put(s, new Namespace(s, new ArrayList<String>(this.namespaceService.getPrefixes(s))));
ret.put(s, new Namespace(s, new ArrayList<>(this.namespaceService.getPrefixes(s))));
}
return new Namespaces(ret);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testGetAllNodeInfoOfMultipleNodes() throws IOException, JSONExceptio

@Test
public void testGetAllNodeInfoWithNoNodesListed() throws IOException {
String jsonString = json("{}");
String jsonString = json("");

final CloseableHttpClient httpclient = HttpClients.createDefault();
final String url = makeAlfrescoBaseurl("admin", "admin") + "/apix/v1/nodes/nodeInfo";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void testCopyFileDuplicateName() {
@Test
public void testCopyFolderDuplicateName() {
final NodeRef childRef = nodeService.getChildAssociations(mainTestFolder).get(0).getTarget();
final String newName = nodeService.getMetadata(childRef).properties.get(c.apix(ContentModel.PROP_NAME)).get(0);
final String newName = nodeService.getMetadata(childRef).getProperties().get(c.apix(ContentModel.PROP_NAME)).get(0);
CreateNodeOptions createNodeOptions = getCreateNodeOptions(mainTestFolder, newName,
null, null, copyFromFolder);
NodeRef newRef = transactionService.getRetryingTransactionHelper()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void checkCreatedNode(NodeRef newRef, CreateNodeOptions createNodeOptions
assertEquals(createNodeOptions.getParent(), nodeService.getParentAssociations(newRef).get(0).getTarget().toString());

if (createNodeOptions.getType() != null) {
assertEquals(createNodeOptions.getType(), nodeService.getMetadata(newRef).type.toString());
assertEquals(createNodeOptions.getType(), nodeService.getMetadata(newRef).getType().toString());
}

if (createNodeOptions.getCopyFrom() != null) {
Expand All @@ -116,13 +116,13 @@ public void checkCreatedNode(NodeRef newRef, CreateNodeOptions createNodeOptions

if (createNodeOptions.getProperties() != null) {
for (Map.Entry<QName, String[]> property : createNodeOptions.getProperties().entrySet()) {
assertArrayEquals(property.getValue(), nodeService.getMetadata(newRef).properties.get(property.getKey()).toArray());
assertArrayEquals(property.getValue(), nodeService.getMetadata(newRef).getProperties().get(property.getKey()).toArray());
}
}

if (createNodeOptions.getAspectsToAdd() != null) {
for (QName aspect : createNodeOptions.getAspectsToAdd()) {
assertNotNull(nodeService.getMetadata(newRef).aspects
assertNotNull(nodeService.getMetadata(newRef).getAspects()
.stream()
.filter(testAspect -> testAspect.equals(aspect))
.findFirst()
Expand All @@ -132,7 +132,7 @@ public void checkCreatedNode(NodeRef newRef, CreateNodeOptions createNodeOptions

if (createNodeOptions.getAspectsToRemove() != null) {
for (QName aspect : createNodeOptions.getAspectsToRemove()) {
assertNull(nodeService.getMetadata(newRef).aspects
assertNull(nodeService.getMetadata(newRef).getAspects()
.stream()
.filter(testAspect -> testAspect.equals(aspect))
.findFirst()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package eu.xenit.apix.rest.v1.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
import eu.xenit.apix.alfresco.ApixToAlfrescoConversion;
import eu.xenit.apix.data.NodeRef;
import eu.xenit.apix.versionhistory.Version;
import eu.xenit.apix.versionhistory.VersionHistory;
import java.io.IOException;
import java.util.HashMap;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.version.VersionBaseModel;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeService;
Expand All @@ -22,6 +15,7 @@
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
Expand All @@ -36,10 +30,17 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.io.IOException;
import java.util.HashMap;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;


public class VersionHistoryTest extends RestV1BaseTest {

private final static Logger logger = LoggerFactory.getLogger(VersionHistoryTest.class);
private static final Logger logger = LoggerFactory.getLogger(VersionHistoryTest.class);
@Autowired
@Qualifier("TransactionService")
TransactionService transactionService;
Expand Down Expand Up @@ -119,12 +120,10 @@ public void testSetVersionHistoryWithoutBody() throws IOException {
return null;
}, true, true);

int statusCode = Request.Put(versionHistoryUrl)
HttpResponse response = Request.Put(versionHistoryUrl)
.execute()
.returnResponse()
.getStatusLine()
.getStatusCode();
assertEquals(200, statusCode);
.returnResponse();
assertEquals(200, response.getStatusLine().getStatusCode());

transactionService.getRetryingTransactionHelper()
.doInTransaction(() -> {
Expand Down Expand Up @@ -170,12 +169,11 @@ public void testSetVersionHistoryWithoutBody() throws IOException {

HttpPut httpPut = new HttpPut(versionHistoryUrl2);
httpPut.setEntity(new StringEntity(json(requestBody), ContentType.APPLICATION_JSON));
int statusCode2 = HttpClients.createDefault()
.execute(httpPut)
CloseableHttpResponse httpResponse = HttpClients.createDefault()
.execute(httpPut);
assertEquals(200, httpResponse
.getStatusLine()
.getStatusCode();

assertEquals(200, statusCode2);
.getStatusCode());

transactionService.getRetryingTransactionHelper()
.doInTransaction(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testGetAllNodeInfoOfMultipleNodes() throws IOException, JSONExceptio

@Test
public void testGetAllNodeInfoWithNoNodesListed() throws IOException {
String jsonString = json("{}");
String jsonString = json("");

final CloseableHttpClient httpclient = HttpClients.createDefault();
final String url = makeAlfrescoBaseurl("admin", "admin") + "/apix/v2/nodes/nodeInfo";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,14 @@ public void TestGetMetadata() {
NodeMetadata metadatas = service.getMetadata(c.apix(roots.iterator().next()));
logger.debug(metadatas.toString().replaceAll(",", ",\n"));

assertEquals(c.apix(roots.iterator().next()), metadatas.id);
assertEquals(c.apix(roots.iterator().next()), metadatas.getId());

assertTrue(metadatas.properties.containsKey(c.apix(ContentModel.PROP_NAME)));
assertTrue(metadatas.getProperties().containsKey(c.apix(ContentModel.PROP_NAME)));
}

private Boolean nodeIsInMetaList(NodeRef node, List<NodeMetadata> metadatas) {
for (NodeMetadata metadata : metadatas) {
if (metadata.id.equals(node.toString())) {
if (metadata.getId().equals(node.toString())) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ public ConfigurationFile(NodeRef nodeRef, NodeMetadata metadata) {
this.metadata = metadata;
}

public ConfigurationFile() {
}

public ConfigurationFile(String content, NodeRef nodeRef, NodeMetadata metadata, NodePath path, Object parsedContent) {
this.content = content;
this.nodeRef = nodeRef;
this.metadata = metadata;
this.path = path;
this.parsedContent = parsedContent;
}

public NodeRef getNodeRef() {
return nodeRef;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ public class ConfigurationFileFlags {
public boolean addMetadata;
public boolean addNodeRef;

public ConfigurationFileFlags() {
}

public ConfigurationFileFlags(boolean addContent, boolean addPath, boolean addParsedContent, boolean addMetadata,
boolean addNodeRef) {
boolean addNodeRef) {
this.addContent = addContent;
this.addPath = addPath;
this.addParsedContent = addParsedContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class Configurations {

private List<ConfigurationFile> files;

public Configurations() {
}

public Configurations(List<ConfigurationFile> files) {
this.files = new ArrayList<>(files);
this.files.sort(new ConfigurationFileComparator());
Expand Down
Loading