diff --git a/pom.xml b/pom.xml index d8b8c4e..4480218 100644 --- a/pom.xml +++ b/pom.xml @@ -5,10 +5,10 @@ com.inteligr8.alfresco aps-public-rest-client - 2.0-SNAPSHOT + 2.0-SNAPSHOT-jersey Alfresco Process Services ReST API Client for Java - An APS Client library for building REST API clients that support either the CXF and Jersey frameworks + An APS Client library for building Jersey-based REST API clients https://bitbucket.org/inteligr8/aps-public-rest-client @@ -46,13 +46,14 @@ 5.7.2 5.2.14.RELEASE + 2.35 com.inteligr8 common-rest-client - 2.0.1 + 2.0.1-jersey com.inteligr8.alfresco @@ -84,10 +85,49 @@ 2.17.2 test + + + + org.glassfish.jersey.inject + jersey-hk2 + ${jersey.version} + test + + + org.glassfish.jersey.media + jersey-media-json-jackson + ${jersey.version} + test + + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + add-jaxrs-src + add-source + + + src/main/jersey + + + + + add-test-src + add-test-source + + + src/test/jersey + + + + + maven-surefire-plugin 3.0.0-M5 diff --git a/src/main/jersey/com/inteligr8/alfresco/activiti/ApsClientJerseyConfiguration.java b/src/main/jersey/com/inteligr8/alfresco/activiti/ApsClientJerseyConfiguration.java new file mode 100644 index 0000000..de72526 --- /dev/null +++ b/src/main/jersey/com/inteligr8/alfresco/activiti/ApsClientJerseyConfiguration.java @@ -0,0 +1,46 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package com.inteligr8.alfresco.activiti; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.inteligr8.rs.ClientJerseyConfiguration; + +/** + * This class provides a POJO & Spring-based implementation of the + * ClientJerseyConfiguration interface. You can use it outside of the Spring + * context, but you will need the spring-context and spring-beans libraries in + * your non-Spring application. + * + * @author brian@inteligr8.com + */ +@Configuration +@ComponentScan +public class ApsClientJerseyConfiguration extends ApsClientConfiguration implements ClientJerseyConfiguration { + + @Value("${process.service.jersey.putBodyRequired:true}") + private boolean putBodyRequired; + + public boolean isPutBodyRequired() { + return this.putBodyRequired; + } + + public void setPutBodyRequired(boolean putBodyRequired) { + this.putBodyRequired = putBodyRequired; + } + +} diff --git a/src/main/jersey/com/inteligr8/alfresco/activiti/ApsClientJerseyImpl.java b/src/main/jersey/com/inteligr8/alfresco/activiti/ApsClientJerseyImpl.java new file mode 100644 index 0000000..bb3c1e1 --- /dev/null +++ b/src/main/jersey/com/inteligr8/alfresco/activiti/ApsClientJerseyImpl.java @@ -0,0 +1,43 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package com.inteligr8.alfresco.activiti; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +import com.inteligr8.rs.ClientJerseyImpl; + +/** + * This class provides a POJO & Spring-based implementation of the Jersey + * client configured for APS. You can use it outside of the Spring context, + * but you will need the spring-context and spring-beans libraries in your + * non-Spring application. + * + * @author brian@inteligr8.com + */ +@Component("aps.client.jersey") +@Lazy +public class ApsClientJerseyImpl extends ClientJerseyImpl { + + /** + * This constructor is for Spring and POJO use + */ + @Autowired + public ApsClientJerseyImpl(ApsClientJerseyConfiguration config) { + super(config); + } + +} diff --git a/src/main/jersey/com/inteligr8/alfresco/activiti/ApsPublicRestApiJerseyImpl.java b/src/main/jersey/com/inteligr8/alfresco/activiti/ApsPublicRestApiJerseyImpl.java new file mode 100644 index 0000000..d36fa5a --- /dev/null +++ b/src/main/jersey/com/inteligr8/alfresco/activiti/ApsPublicRestApiJerseyImpl.java @@ -0,0 +1,39 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package com.inteligr8.alfresco.activiti; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +/** + * This class provides the Jersey client to the JAX-RS API for the APS Public + * ReST API. + * + * @author brian@inteligr8.com + */ +@Component("aps.api.jersey") +@Lazy +public class ApsPublicRestApiJerseyImpl extends ApsPublicRestApiImpl implements ApsPublicRestJerseyApi { + + /** + * This constructor is for Spring or POJO use + */ + @Autowired + public ApsPublicRestApiJerseyImpl(ApsClientJerseyImpl client) { + super(client); + } + +} diff --git a/src/test/jersey/META-INF/services/javax.ws.rs.client.ClientBuilder b/src/test/jersey/META-INF/services/javax.ws.rs.client.ClientBuilder new file mode 100644 index 0000000..48b9fa5 --- /dev/null +++ b/src/test/jersey/META-INF/services/javax.ws.rs.client.ClientBuilder @@ -0,0 +1 @@ +org.glassfish.jersey.client.JerseyClientBuilder \ No newline at end of file diff --git a/src/test/jersey/com/inteligr8/alfresco/activiti/ArrayResponseUnitTest.java b/src/test/jersey/com/inteligr8/alfresco/activiti/ArrayResponseUnitTest.java new file mode 100644 index 0000000..a30f0b2 --- /dev/null +++ b/src/test/jersey/com/inteligr8/alfresco/activiti/ArrayResponseUnitTest.java @@ -0,0 +1,51 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package com.inteligr8.alfresco.activiti; + +import java.util.List; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIf; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import com.inteligr8.alfresco.activiti.model.Tenant; +import com.inteligr8.rs.ClientConfiguration; + +@TestPropertySource(locations = {"/local.properties"}) +@SpringJUnitConfig(classes = {ApsClientJerseyConfiguration.class, ApsPublicRestApiJerseyImpl.class, ApsClientJerseyImpl.class}) +public class ArrayResponseUnitTest extends ConditionalIT { + + @Autowired + @Qualifier("aps.api.jersey") + private ApsPublicRestApiImpl api; + + @Override + public ClientConfiguration getConfiguration() { + return this.api.getClient().getConfig(); + } + + @Test + @EnabledIf("hostExists") + public void testTenants() { + List objs = this.api.getAdminApi().getTenants(); + + Assertions.assertNotNull(objs); + } + +} diff --git a/src/test/jersey/com/inteligr8/alfresco/activiti/ConnectionJerseyClientPojoIT.java b/src/test/jersey/com/inteligr8/alfresco/activiti/ConnectionJerseyClientPojoIT.java new file mode 100644 index 0000000..0de69df --- /dev/null +++ b/src/test/jersey/com/inteligr8/alfresco/activiti/ConnectionJerseyClientPojoIT.java @@ -0,0 +1,45 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package com.inteligr8.alfresco.activiti; + +import org.junit.jupiter.api.BeforeAll; + +import com.inteligr8.rs.ClientConfiguration; + +public class ConnectionJerseyClientPojoIT extends ConnectionClientIT { + + private static ApsPublicRestApiImpl api; + + @BeforeAll + public static void initClient() { + ApsClientJerseyConfiguration config = new ApsClientJerseyConfiguration(); + config.setBaseUrl("http://localhost:8080/activiti-app"); + config.setBasicAuthUsername("admin"); + config.setBasicAuthPassword("admin"); + + api = new ApsPublicRestApiJerseyImpl( + new ApsClientJerseyImpl(config)); + } + + public ApsPublicRestApiImpl getApi() { + return api; + } + + @Override + public ClientConfiguration getConfiguration() { + return api.getClient().getConfig(); + } + +} diff --git a/src/test/jersey/com/inteligr8/alfresco/activiti/ConnectionJerseyClientSpringIT.java b/src/test/jersey/com/inteligr8/alfresco/activiti/ConnectionJerseyClientSpringIT.java new file mode 100644 index 0000000..60cd4c2 --- /dev/null +++ b/src/test/jersey/com/inteligr8/alfresco/activiti/ConnectionJerseyClientSpringIT.java @@ -0,0 +1,41 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package com.inteligr8.alfresco.activiti; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import com.inteligr8.rs.ClientConfiguration; + +@TestPropertySource(locations = {"/local.properties"}) +@SpringJUnitConfig(classes = {ApsClientJerseyConfiguration.class, ApsPublicRestApiJerseyImpl.class, ApsClientJerseyImpl.class}) +public class ConnectionJerseyClientSpringIT extends ConnectionClientIT { + + @Autowired + @Qualifier("aps.api.jersey") + private ApsPublicRestApiImpl api; + + public ApsPublicRestApiImpl getApi() { + return this.api; + } + + @Override + public ClientConfiguration getConfiguration() { + return this.api.getClient().getConfig(); + } + +} diff --git a/src/test/jersey/com/inteligr8/alfresco/activiti/ResultListResponseUnitTest.java b/src/test/jersey/com/inteligr8/alfresco/activiti/ResultListResponseUnitTest.java new file mode 100644 index 0000000..f5ae720 --- /dev/null +++ b/src/test/jersey/com/inteligr8/alfresco/activiti/ResultListResponseUnitTest.java @@ -0,0 +1,57 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package com.inteligr8.alfresco.activiti; + +import java.util.List; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIf; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import com.inteligr8.alfresco.activiti.model.GroupLight; +import com.inteligr8.alfresco.activiti.model.ResultList; +import com.inteligr8.alfresco.activiti.model.UserLight; +import com.inteligr8.rs.ClientConfiguration; + +@TestPropertySource(locations = {"/local.properties"}) +@SpringJUnitConfig(classes = {ApsClientJerseyConfiguration.class, ApsPublicRestApiJerseyImpl.class, ApsClientJerseyImpl.class}) +public class ResultListResponseUnitTest extends ConditionalIT { + + @Autowired + @Qualifier("aps.api.jersey") + private ApsPublicRestApiImpl api; + + @Override + public ClientConfiguration getConfiguration() { + return this.api.getClient().getConfig(); + } + + @Test + @EnabledIf("hostExists") + public void testGroupMembers() { + List groups = this.api.getAdminApi().getGroups(1L, false, false); + Assertions.assertFalse(groups.isEmpty()); + + for (GroupLight group : groups) { + ResultList users = this.api.getAdminApi().getMembers(group.getId(), null, null, null); + Assertions.assertNotNull(users); + } + } + +}