private void verifyIntents(Class<?> serviceImplClass, JavaImplementation type) {
if ( !(type instanceof PolicySetAttachPoint) ) {
fail("No Intents on the service ");
}
Requires serviceImplIntentAnnotation = (Requires)serviceImplClass.getAnnotation(Requires.class);
if (serviceImplIntentAnnotation != null) {
String[] serviceImplIntents = serviceImplIntentAnnotation.value();
List<Intent> requiredIntents = ((PolicySetAttachPoint)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());
}
Map<String, Intent> intentMap = new HashMap<String, Intent>();
for (Intent intent : requiredIntents) {
intentMap.put(intent.getName().getLocalPart(), intent);
}
for (String intent : interfaceIntents) {
assertTrue("Interface " + service.getName()
+ " did not contain Service Interface intent "
+ intent, intentMap.containsKey(intent));
}
}
}
for (Method method : interfaceClass.getDeclaredMethods()) {
Requires methodIntentAnnotation = method.getAnnotation(Requires.class);
// Verify that each of the Intents on each of the Service
// Interface Methods exist on their associated operation.
if (methodIntentAnnotation != null) {
String[] methodIntents = methodIntentAnnotation.value();
if (methodIntents.length > 0) {
List<Intent> requiredIntents = null;
for ( ConfiguredOperation confOp : service.getConfiguredOperations() ) {
if ( confOp.getName().equals(method.getName()) &&
confOp.getContractName().equals(service.getName()) ) {
requiredIntents = confOp.getRequiredIntents();
}
}
if (requiredIntents == null || requiredIntents.size() == 0) {
fail("No Intents on operation " + method.getName());
}
for (String intent : methodIntents) {
boolean found = false;
for (Intent requiredIntent: requiredIntents) {
if (requiredIntent.getName().getLocalPart().equals(intent)) {
found = true;
break;
}
}
assertTrue("Operation " + method.getName()
+ " did not contain Service Interface method intent "
+ intent, found);
}
}
}
}
for (Method method : serviceImplClass.getDeclaredMethods()) {
Requires methodIntentAnnotation = method.getAnnotation(Requires.class);
// Verify that each of the Intents on each of the Service
// Implementation Methods exist on their associated
// operation.
if (methodIntentAnnotation != null) {
String[] methodIntents = methodIntentAnnotation.value();
if (methodIntents.length > 0) {
List<Intent> requiredIntents = null;
for ( ConfiguredOperation confOp : ((OperationsConfigurator)type).getConfiguredOperations() ) {
if ( confOp.getName().equals(method.getName()) ) {
requiredIntents = confOp.getRequiredIntents();