Skip to content
Permalink
Browse files
[DOSGI-262] Add support for Features annotation
  • Loading branch information
cschneider committed Apr 10, 2017
1 parent 43ec611 commit a3a97938043a250fcf1e3c76b861600e4a9ee83f
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
@@ -31,6 +31,7 @@
import org.apache.cxf.dosgi.common.api.IntentsProvider;
import org.apache.cxf.dosgi.common.intent.IntentManager;
import org.apache.cxf.dosgi.common.util.PropertyHelper;
import org.apache.cxf.feature.Features;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.FrameworkUtil;
@@ -197,6 +198,16 @@ public List<Object> getIntentsFromService(Object serviceBean) {
if (serviceBean instanceof IntentsProvider) {
intents.addAll(((IntentsProvider)serviceBean).getIntents());
}
Features features = serviceBean.getClass().getAnnotation(Features.class);
if (features != null && features.classes() != null) {
for (Class<?> clazz : features.classes()) {
try {
intents.add(clazz.newInstance());
} catch (Exception e) {
throw new RuntimeException("Could not instantiate feature from class " + clazz.getName(), e);
}
}
}
return intents;
}

@@ -0,0 +1,27 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.cxf.dosgi.common.intent.impl;

import org.apache.cxf.feature.Features;
import org.apache.cxf.transport.common.gzip.GZIPFeature;

@Features(classes = GZIPFeature.class)
public class DummyServiceWithLogging {

}
@@ -0,0 +1,34 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.cxf.dosgi.common.intent.impl;

import java.util.Arrays;
import java.util.List;

import org.apache.cxf.dosgi.common.api.IntentsProvider;
import org.apache.cxf.transport.common.gzip.GZIPFeature;

public class DummyServiceWithLoggingIP implements IntentsProvider {

@Override
public List<?> getIntents() {
return Arrays.asList(new GZIPFeature());
}

}
@@ -0,0 +1,46 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.cxf.dosgi.common.intent.impl;

import java.util.List;

import org.apache.cxf.transport.common.gzip.GZIPFeature;
import org.junit.Assert;
import org.junit.Test;

public class IntentManagerImplTest {

@Test
public void testIntentsFromFeatureAnn() {
IntentManagerImpl im = new IntentManagerImpl();
List<Object> intents = im.getIntentsFromService(new DummyServiceWithLogging());
Assert.assertEquals(1, intents.size());
Object feature = intents.iterator().next();
Assert.assertEquals(GZIPFeature.class, feature.getClass());
}

@Test
public void testIntentsFromIntentsProvider() {
IntentManagerImpl im = new IntentManagerImpl();
List<Object> intents = im.getIntentsFromService(new DummyServiceWithLoggingIP());
Assert.assertEquals(1, intents.size());
Object feature = intents.iterator().next();
Assert.assertEquals(GZIPFeature.class, feature.getClass());
}
}

0 comments on commit a3a9793

Please sign in to comment.