private void verifyIntents(Class<?> serviceImplClass, JavaImplementation type) {
if ( !(type instanceof PolicySubject) ) {
fail("No Intents on the service ");
}
Requires serviceImplIntentAnnotation = (Requires)serviceImplClass.getAnnotation(Requires.class);
if (serviceImplIntentAnnotation != null) {
String[] serviceImplIntents = serviceImplIntentAnnotation.value();
List<Intent> requiredIntents = ((PolicySubject)type).getRequiredIntents();
if (serviceImplIntents.length > 0) {
if (requiredIntents == null || requiredIntents.size() == 0) {
fail("No Intents on the service ");
}
Map<String, Intent> intentMap = new HashMap<String, Intent>();
for (Intent intent : requiredIntents) {
intentMap.put(intent.getName().getLocalPart(), intent);
}
for (String intent : serviceImplIntents) {
assertTrue("ComponentType for Service class " + serviceImplClass.getName()
+ " did not contain Service Implementation intent "
+ intent, intentMap.containsKey(intent));
}
}
}
// This should match what was specified on @Service for a Service Implementation
// If we use these to get the Service names and we get a null Service
// name then it would seem that wrong values were put on the @Service annotation
// or the wrong interfaces were specified on the implements list of the class
// statement?
Map<String, org.apache.tuscany.sca.assembly.Service> serviceMap = new HashMap<String, org.apache.tuscany.sca.assembly.Service>();
for (org.apache.tuscany.sca.assembly.Service service: type.getServices()) {
serviceMap.put(service.getName(), service);
}
for (Class<?> interfaceClass : serviceImplClass.getInterfaces()) {
Requires interfaceIntentAnnotation = (Requires)interfaceClass.getAnnotation(Requires.class);
org.apache.tuscany.sca.assembly.Service service = serviceMap.get(interfaceClass.getSimpleName());
if (service == null) {
fail("No service defined for interface " + interfaceClass.getSimpleName()
+ " on Service Implementation "
+ serviceImplClass.getName());
}
if (interfaceIntentAnnotation != null) {
String[] interfaceIntents = interfaceIntentAnnotation.value();
List<Intent> requiredIntents = service.getInterfaceContract().getInterface().getRequiredIntents();
if (interfaceIntents.length > 0) {
if (requiredIntents == null || requiredIntents.size() == 0) {
fail("No Intents on the service " + service.getName());
}