[Major] changed constructor of StrolchComponent
Should have interface ComponentContainer in constructor
This commit is contained in:
parent
eebbad2b48
commit
100764af2c
|
@ -16,49 +16,52 @@
|
||||||
package li.strolch.rest;
|
package li.strolch.rest;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.StrolchAgent;
|
|
||||||
import li.strolch.agent.api.StrolchComponent;
|
import li.strolch.agent.api.StrolchComponent;
|
||||||
import ch.eitchnet.utils.dbc.DBC;
|
import ch.eitchnet.utils.dbc.DBC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class AgentRef {
|
public class RestfulStrolchComponent extends StrolchComponent {
|
||||||
|
|
||||||
private static final AgentRef instance;
|
private static RestfulStrolchComponent instance;
|
||||||
|
|
||||||
static {
|
/**
|
||||||
instance = new AgentRef();
|
* @param container
|
||||||
|
* @param componentName
|
||||||
|
*/
|
||||||
|
public RestfulStrolchComponent(ComponentContainer container, String componentName) {
|
||||||
|
super(container, componentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AgentRef getInstance() {
|
@Override
|
||||||
return instance;
|
public void start() {
|
||||||
|
DBC.PRE.assertNull("Instance is already set! This component is a singleton resource!", instance);
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
super.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private StrolchAgent agent;
|
@Override
|
||||||
|
public void stop() {
|
||||||
private AgentRef() {
|
instance = null;
|
||||||
// singleton
|
super.stop();
|
||||||
}
|
|
||||||
|
|
||||||
public void init(StrolchAgent agent) {
|
|
||||||
DBC.PRE.assertNull("AgentRef has already been configured!", this.agent);
|
|
||||||
this.agent = agent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the agent
|
* @return the RestfulStrolchComponent
|
||||||
*/
|
*/
|
||||||
public StrolchAgent getAgent() {
|
public static RestfulStrolchComponent getInstance() {
|
||||||
DBC.PRE.assertNotNull("Not yet initialized!", agent);
|
DBC.PRE.assertNotNull("Not yet initialized!", instance);
|
||||||
return this.agent;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ComponentContainer getContainer() {
|
public ComponentContainer getContainer() {
|
||||||
return getAgent().getContainer();
|
return super.getContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends StrolchComponent> T getComponent(Class<T> clazz) {
|
public <T extends StrolchComponent> T getComponent(Class<T> clazz) {
|
||||||
return getAgent().getContainer().getComponent(clazz);
|
return getContainer().getComponent(clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -35,7 +35,7 @@ import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.rest.AgentRef;
|
import li.strolch.rest.RestfulStrolchComponent;
|
||||||
import li.strolch.rest.model.AgentOverview;
|
import li.strolch.rest.model.AgentOverview;
|
||||||
import li.strolch.rest.model.ElementMapOverview;
|
import li.strolch.rest.model.ElementMapOverview;
|
||||||
import li.strolch.rest.model.ElementMapType;
|
import li.strolch.rest.model.ElementMapType;
|
||||||
|
@ -75,7 +75,7 @@ public class Inspector {
|
||||||
public Response getAgent() {
|
public Response getAgent() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ComponentContainer container = AgentRef.getInstance().getContainer();
|
ComponentContainer container = RestfulStrolchComponent.getInstance().getContainer();
|
||||||
Set<String> realmNames = container.getRealmNames();
|
Set<String> realmNames = container.getRealmNames();
|
||||||
List<RealmOverview> realmOverviews = new ArrayList<>(realmNames.size());
|
List<RealmOverview> realmOverviews = new ArrayList<>(realmNames.size());
|
||||||
for (String realmName : realmNames) {
|
for (String realmName : realmNames) {
|
||||||
|
@ -122,7 +122,7 @@ public class Inspector {
|
||||||
public Response getRealm(@PathParam("realm") String realm) {
|
public Response getRealm(@PathParam("realm") String realm) {
|
||||||
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
||||||
|
|
||||||
StrolchRealm strolchRealm = AgentRef.getInstance().getContainer().getRealm(realm);
|
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
|
||||||
List<ElementMapsOverview> elementMapOverviews = new ArrayList<>(2);
|
List<ElementMapsOverview> elementMapOverviews = new ArrayList<>(2);
|
||||||
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ public class Inspector {
|
||||||
@Path("{realm}/resource")
|
@Path("{realm}/resource")
|
||||||
public Response getResourcesOverview(@PathParam("realm") String realm) {
|
public Response getResourcesOverview(@PathParam("realm") String realm) {
|
||||||
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
||||||
StrolchRealm strolchRealm = AgentRef.getInstance().getContainer().getRealm(realm);
|
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
|
||||||
|
|
||||||
ElementMapOverview resourcesOverview;
|
ElementMapOverview resourcesOverview;
|
||||||
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
||||||
|
@ -207,7 +207,7 @@ public class Inspector {
|
||||||
@Path("{realm}/order")
|
@Path("{realm}/order")
|
||||||
public Response getOrdersOverview(@PathParam("realm") String realm) {
|
public Response getOrdersOverview(@PathParam("realm") String realm) {
|
||||||
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
||||||
StrolchRealm strolchRealm = AgentRef.getInstance().getContainer().getRealm(realm);
|
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
|
||||||
|
|
||||||
ElementMapOverview ordersOverview;
|
ElementMapOverview ordersOverview;
|
||||||
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
||||||
|
@ -255,7 +255,7 @@ public class Inspector {
|
||||||
@Path("{realm}/resource/{type}")
|
@Path("{realm}/resource/{type}")
|
||||||
public Response getResourceTypeDetails(@PathParam("realm") String realm, @PathParam("type") String type) {
|
public Response getResourceTypeDetails(@PathParam("realm") String realm, @PathParam("type") String type) {
|
||||||
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
||||||
StrolchRealm strolchRealm = AgentRef.getInstance().getContainer().getRealm(realm);
|
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
|
||||||
|
|
||||||
TypeDetail typeDetail;
|
TypeDetail typeDetail;
|
||||||
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
||||||
|
@ -295,7 +295,7 @@ public class Inspector {
|
||||||
@Path("{realm}/order/{type}")
|
@Path("{realm}/order/{type}")
|
||||||
public Response getOrderTypeDetails(@PathParam("realm") String realm, @PathParam("type") String type) {
|
public Response getOrderTypeDetails(@PathParam("realm") String realm, @PathParam("type") String type) {
|
||||||
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
||||||
StrolchRealm strolchRealm = AgentRef.getInstance().getContainer().getRealm(realm);
|
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
|
||||||
|
|
||||||
TypeDetail typeDetail;
|
TypeDetail typeDetail;
|
||||||
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
||||||
|
@ -339,7 +339,7 @@ public class Inspector {
|
||||||
public Response getResource(@PathParam("realm") String realm, @PathParam("type") String type,
|
public Response getResource(@PathParam("realm") String realm, @PathParam("type") String type,
|
||||||
@PathParam("id") String id) {
|
@PathParam("id") String id) {
|
||||||
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
||||||
StrolchRealm strolchRealm = AgentRef.getInstance().getContainer().getRealm(realm);
|
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
|
||||||
|
|
||||||
Resource resource;
|
Resource resource;
|
||||||
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
||||||
|
@ -361,7 +361,7 @@ public class Inspector {
|
||||||
public Response getOrder(@PathParam("realm") String realm, @PathParam("type") String type,
|
public Response getOrder(@PathParam("realm") String realm, @PathParam("type") String type,
|
||||||
@PathParam("id") String id) {
|
@PathParam("id") String id) {
|
||||||
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
|
||||||
StrolchRealm strolchRealm = AgentRef.getInstance().getContainer().getRealm(realm);
|
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
|
||||||
|
|
||||||
Order order;
|
Order order;
|
||||||
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
try (StrolchTransaction tx = strolchRealm.openTx()) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import li.strolch.agent.api.VersionQueryResult;
|
import li.strolch.agent.api.VersionQueryResult;
|
||||||
import li.strolch.rest.AgentRef;
|
import li.strolch.rest.RestfulStrolchComponent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -34,7 +34,8 @@ public class VersionQuery {
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Response getVersions() {
|
public Response getVersions() {
|
||||||
VersionQueryResult versionQueryResult = AgentRef.getInstance().getAgent().getVersion();
|
VersionQueryResult versionQueryResult = RestfulStrolchComponent.getInstance().getContainer().getAgent()
|
||||||
|
.getVersion();
|
||||||
GenericEntity<VersionQueryResult> entity = new GenericEntity<VersionQueryResult>(versionQueryResult,
|
GenericEntity<VersionQueryResult> entity = new GenericEntity<VersionQueryResult>(versionQueryResult,
|
||||||
VersionQueryResult.class) {
|
VersionQueryResult.class) {
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.net.URI;
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import li.strolch.rest.AgentRef;
|
|
||||||
import li.strolch.rest.StrolchRestfulClasses;
|
import li.strolch.rest.StrolchRestfulClasses;
|
||||||
import li.strolch.rest.StrolchRestfulExceptionMapper;
|
import li.strolch.rest.StrolchRestfulExceptionMapper;
|
||||||
import li.strolch.testbase.runtime.RuntimeMock;
|
import li.strolch.testbase.runtime.RuntimeMock;
|
||||||
|
@ -62,8 +61,6 @@ public abstract class AbstractRestfulTest {
|
||||||
runtimeMock.mockRuntime(rootPath, configSrc);
|
runtimeMock.mockRuntime(rootPath, configSrc);
|
||||||
runtimeMock.startContainer(rootPath);
|
runtimeMock.startContainer(rootPath);
|
||||||
|
|
||||||
AgentRef.getInstance().init(runtimeMock.getAgent());
|
|
||||||
|
|
||||||
// create a resource config that scans for JAX-RS resources and providers
|
// create a resource config that scans for JAX-RS resources and providers
|
||||||
// in com.example package
|
// in com.example package
|
||||||
final ResourceConfig rc = new ResourceConfig();
|
final ResourceConfig rc = new ResourceConfig();
|
||||||
|
|
|
@ -23,9 +23,6 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import li.strolch.agent.api.AgentVersion;
|
|
||||||
import li.strolch.agent.api.ComponentVersion;
|
|
||||||
import li.strolch.agent.api.VersionQueryResult;
|
|
||||||
import li.strolch.rest.model.AgentOverview;
|
import li.strolch.rest.model.AgentOverview;
|
||||||
import li.strolch.rest.model.ElementMapOverview;
|
import li.strolch.rest.model.ElementMapOverview;
|
||||||
import li.strolch.rest.model.ElementMapType;
|
import li.strolch.rest.model.ElementMapType;
|
||||||
|
@ -42,7 +39,7 @@ import com.sun.jersey.api.client.GenericType;
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class RestfulServicesTest extends AbstractRestfulTest {
|
public class InspectorTest extends AbstractRestfulTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldGetAgent() {
|
public void shouldGetAgent() {
|
||||||
|
@ -163,32 +160,4 @@ public class RestfulServicesTest extends AbstractRestfulTest {
|
||||||
assertTrue(entity
|
assertTrue(entity
|
||||||
.contains("\"date\":\"2012-11-30T18:12:05.628+01:00\",\"state\":\"CREATED\",\"parameterBags\""));
|
.contains("\"date\":\"2012-11-30T18:12:05.628+01:00\",\"state\":\"CREATED\",\"parameterBags\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldQueryVersion() {
|
|
||||||
|
|
||||||
// query
|
|
||||||
ClientResponse response = getClientResponse("/strolch/version");
|
|
||||||
VersionQueryResult versionQueryResult = response.getEntity(new GenericType<VersionQueryResult>() {
|
|
||||||
});
|
|
||||||
|
|
||||||
if (versionQueryResult.hasErrors()) {
|
|
||||||
for (String error : versionQueryResult.getErrors()) {
|
|
||||||
logger.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AgentVersion agentVersion = versionQueryResult.getAgentVersion();
|
|
||||||
logger.info(agentVersion.toString());
|
|
||||||
List<ComponentVersion> componentVersions = versionQueryResult.getComponentVersions();
|
|
||||||
assertEquals(4, componentVersions.size());
|
|
||||||
for (ComponentVersion version : componentVersions) {
|
|
||||||
logger.info(version.toString());
|
|
||||||
assertEquals("li.strolch", agentVersion.getGroupId());
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("StrolchPersistenceTest", agentVersion.getAgentName());
|
|
||||||
assertEquals("li.strolch", agentVersion.getGroupId());
|
|
||||||
assertEquals("li.strolch.agent", agentVersion.getArtifactId());
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package li.strolch.rest.inspector.test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import li.strolch.agent.api.AgentVersion;
|
||||||
|
import li.strolch.agent.api.ComponentVersion;
|
||||||
|
import li.strolch.agent.api.VersionQueryResult;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.sun.jersey.api.client.ClientResponse;
|
||||||
|
import com.sun.jersey.api.client.GenericType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public class VersionQueryTest extends AbstractRestfulTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldQueryVersion() {
|
||||||
|
|
||||||
|
// query
|
||||||
|
ClientResponse response = getClientResponse("/strolch/version");
|
||||||
|
VersionQueryResult versionQueryResult = response.getEntity(new GenericType<VersionQueryResult>() {
|
||||||
|
});
|
||||||
|
|
||||||
|
if (versionQueryResult.hasErrors()) {
|
||||||
|
for (String error : versionQueryResult.getErrors()) {
|
||||||
|
logger.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AgentVersion agentVersion = versionQueryResult.getAgentVersion();
|
||||||
|
logger.info(agentVersion.toString());
|
||||||
|
List<ComponentVersion> componentVersions = versionQueryResult.getComponentVersions();
|
||||||
|
assertEquals(5, componentVersions.size());
|
||||||
|
for (ComponentVersion version : componentVersions) {
|
||||||
|
logger.info(version.toString());
|
||||||
|
assertEquals("li.strolch", agentVersion.getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals("StrolchPersistenceTest", agentVersion.getAgentName());
|
||||||
|
assertEquals("li.strolch", agentVersion.getGroupId());
|
||||||
|
assertEquals("li.strolch.agent", agentVersion.getArtifactId());
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,4 +24,11 @@
|
||||||
<privilegeConfigFile>PrivilegeConfig.xml</privilegeConfigFile>
|
<privilegeConfigFile>PrivilegeConfig.xml</privilegeConfigFile>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Component>
|
</Component>
|
||||||
|
<Component>
|
||||||
|
<name>RestfulHandler</name>
|
||||||
|
<api>li.strolch.rest.RestfulStrolchComponent</api>
|
||||||
|
<impl>li.strolch.rest.RestfulStrolchComponent</impl>
|
||||||
|
<Properties>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
</StrolchConfiguration>
|
</StrolchConfiguration>
|
Loading…
Reference in New Issue