You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gu...@apache.org on 2013/07/26 14:33:30 UTC
svn commit: r1507289 [3/3] - in /felix/trunk/ipojo/manipulator:
annotations/src/main/java/org/apache/felix/ipojo/annotations/
manipulator-it/ipojo-manipulator-manipulation-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/
manipulator-i...
Modified: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProviderTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProviderTestCase.java?rev=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProviderTestCase.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/AnnotationMetadataProviderTestCase.java Fri Jul 26 12:33:28 2013
@@ -63,7 +63,11 @@ public class AnnotationMetadataProviderT
}
public byte[] read(String path) throws IOException {
- return resources.get(path);
+ byte[] bytes = resources.get(path);
+ if (bytes == null) {
+ throw new IOException();
+ }
+ return bytes;
}
public void accept(ResourceVisitor visitor) {
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/AnnotationLiteralTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/AnnotationLiteralTestCase.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/AnnotationLiteralTestCase.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/AnnotationLiteralTestCase.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,50 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.model.literal;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.AnnotationLiteral;
+
+import junit.framework.TestCase;
+
+/**
+ * User: guillaume
+ * Date: 28/06/13
+ * Time: 14:40
+ */
+public class AnnotationLiteralTestCase extends TestCase {
+ public void testAnnotationTypeDiscovery() throws Exception {
+
+ FooLiteral fooLiteral = new FooLiteral() {
+ public String value() {
+ return "a";
+ }
+ };
+
+ assertEquals(Foo.class, fooLiteral.annotationType());
+ assertEquals("a", fooLiteral.value());
+
+ }
+
+ private static abstract class FooLiteral extends AnnotationLiteral<Foo> implements Foo { }
+
+ private static @interface Foo {
+ String value();
+ }
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/AnnotationPlaybackTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/AnnotationPlaybackTestCase.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/AnnotationPlaybackTestCase.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/AnnotationPlaybackTestCase.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,196 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.model.literal;
+
+import java.lang.annotation.Annotation;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.AnnotationPlayback;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.types.AnnotationAnnotation;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.types.ArrayAnnotation;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.types.EnumAnnotation;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.types.InnerAnnotation;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.types.Mode;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.types.SimpleTypes;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.types.Support;
+import org.mockito.Mock;
+
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.mockito.MockitoAnnotations;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.Type;
+
+import junit.framework.TestCase;
+
+/**
+ * User: guillaume
+ * Date: 08/07/13
+ * Time: 17:25
+ */
+
+public class AnnotationPlaybackTestCase extends TestCase {
+
+ @Mock
+ private ClassVisitor visitor;
+
+ @Mock
+ private AnnotationVisitor annotationVisitor;
+
+ @Mock
+ private AnnotationVisitor arrayVisitor;
+
+ @Mock
+ private AnnotationVisitor innerAnnotationVisitor;
+
+ @Override
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ public void testSimpleValuesPlayback() throws Exception {
+
+ when(visitor.visitAnnotation(anyString(), anyBoolean())).thenReturn(annotationVisitor);
+
+ AnnotationPlayback playback = new AnnotationPlayback(find(SimpleTypes.class));
+ playback.accept(visitor);
+
+ verify(visitor).visitAnnotation(Type.getType(SimpleTypes.class).getDescriptor(),
+ true);
+ verify(annotationVisitor).visitEnd();
+
+ // Verify simple mono-valued attributes
+ verify(annotationVisitor).visit("aByte", Byte.valueOf((byte) 42));
+ verify(annotationVisitor).visit("aBoolean", Boolean.TRUE);
+ verify(annotationVisitor).visit("anInt", Integer.valueOf(42));
+ verify(annotationVisitor).visit("aLong", Long.valueOf(42));
+ verify(annotationVisitor).visit("aShort", Short.valueOf((short) 42));
+ verify(annotationVisitor).visit("aFloat", Float.valueOf(42));
+ verify(annotationVisitor).visit("aDouble", Double.valueOf(42));
+ verify(annotationVisitor).visit("aChar", Character.valueOf('a'));
+
+ // Verify String & Class
+ verify(annotationVisitor).visit("aString", "42");
+ verify(annotationVisitor).visit("aClass", Type.getType(String.class));
+
+ // Verify array os simple types
+ verify(annotationVisitor).visit("arrayOfByte", new byte[] {(byte) 42});
+ verify(annotationVisitor).visit("arrayOfBoolean", new boolean[] {true, true});
+ verify(annotationVisitor).visit("arrayOfInt", new int[] {42});
+ verify(annotationVisitor).visit("arrayOfLong", new long[] {42});
+ verify(annotationVisitor).visit("arrayOfShort", new short[] {42});
+ verify(annotationVisitor).visit("arrayOfFloat", new float[] {42});
+ verify(annotationVisitor).visit("arrayOfDouble", new double[] {});
+ verify(annotationVisitor).visit("arrayOfChar", new char[] {'a', 'b', 'c'});
+
+ }
+
+ public void testEnumValuesPlayback() throws Exception {
+
+ when(visitor.visitAnnotation(anyString(), anyBoolean())).thenReturn(annotationVisitor);
+
+ AnnotationPlayback playback = new AnnotationPlayback(find(EnumAnnotation.class));
+ playback.accept(visitor);
+
+ verify(visitor).visitAnnotation(Type.getType(EnumAnnotation.class).getDescriptor(),
+ true);
+ verify(annotationVisitor).visitEnd();
+
+ String desc = Type.getType(Mode.class).getDescriptor();
+ verify(annotationVisitor).visitEnum("noDefault", desc, "IN");
+ verify(annotationVisitor).visitEnum("withDefault", desc, "IN");
+ verify(annotationVisitor).visitEnum("withDefaultOverridden", desc, "IN");
+ }
+
+ public void testArrayValuesPlayback() throws Exception {
+
+ AnnotationVisitor arrayOfString = mock(AnnotationVisitor.class);
+ AnnotationVisitor arrayOfEnum = mock(AnnotationVisitor.class);
+ AnnotationVisitor arrayOfClass = mock(AnnotationVisitor.class);
+ AnnotationVisitor arrayOfAnnotation = mock(AnnotationVisitor.class);
+ AnnotationVisitor emptyArray = mock(AnnotationVisitor.class);
+
+ when(visitor.visitAnnotation(anyString(), anyBoolean())).thenReturn(annotationVisitor);
+ when(annotationVisitor.visitArray("arrayOfString")).thenReturn(arrayOfString);
+ when(annotationVisitor.visitArray("arrayOfEnum")).thenReturn(arrayOfEnum);
+ when(annotationVisitor.visitArray("arrayOfClass")).thenReturn(arrayOfClass);
+ when(annotationVisitor.visitArray("arrayOfAnnotation")).thenReturn(arrayOfAnnotation);
+ when(annotationVisitor.visitArray("emptyArray")).thenReturn(emptyArray);
+
+ AnnotationPlayback playback = new AnnotationPlayback(find(ArrayAnnotation.class));
+ playback.accept(visitor);
+
+ verify(visitor).visitAnnotation(Type.getType(ArrayAnnotation.class).getDescriptor(),
+ true);
+ verify(annotationVisitor).visitEnd();
+
+ String desc = Type.getType(Mode.class).getDescriptor();
+
+ verify(arrayOfString).visit(null, "42");
+ verify(arrayOfString).visit(null, "43");
+ verify(arrayOfString).visitEnd();
+
+ verify(arrayOfEnum).visitEnum(null, desc, "IN");
+ verify(arrayOfEnum).visitEnd();
+
+ verify(arrayOfClass).visit(null, Type.getType(Object.class));
+ verify(arrayOfClass).visitEnd();
+
+ verify(arrayOfAnnotation).visitAnnotation(null, Type.getType(InnerAnnotation.class).getDescriptor());
+ verify(arrayOfAnnotation).visitEnd();
+
+ verify(emptyArray).visitEnd();
+
+ }
+
+
+ public void testAnnotationValuesPlayback() throws Exception {
+
+ when(visitor.visitAnnotation(anyString(), anyBoolean())).thenReturn(annotationVisitor);
+ when(annotationVisitor.visitAnnotation("value", Type.getType(InnerAnnotation.class).getDescriptor()))
+ .thenReturn(innerAnnotationVisitor);
+ when(innerAnnotationVisitor.visitArray("arrayOfClass"))
+ .thenReturn(arrayVisitor);
+
+ AnnotationPlayback playback = new AnnotationPlayback(find(AnnotationAnnotation.class));
+ playback.accept(visitor);
+
+ verify(visitor).visitAnnotation(Type.getType(AnnotationAnnotation.class).getDescriptor(),
+ true);
+ verify(annotationVisitor).visitEnd();
+
+ String desc = Type.getType(Mode.class).getDescriptor();
+ verify(innerAnnotationVisitor).visit("aString", "42");
+ verify(innerAnnotationVisitor).visitEnum("modeEnum", desc, "IN");
+ verify(innerAnnotationVisitor).visitEnd();
+
+ verify(arrayVisitor).visit(null, Type.getType(Object.class));
+ verify(arrayVisitor).visitEnd();
+
+ }
+ private Annotation find(final Class<? extends Annotation> type) {
+ return Support.class.getAnnotation(type);
+ }
+
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/AnnotationAnnotation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/AnnotationAnnotation.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/AnnotationAnnotation.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/AnnotationAnnotation.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,36 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.model.literal.types;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * User: guillaume
+ * Date: 09/07/13
+ * Time: 10:15
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface AnnotationAnnotation {
+ InnerAnnotation value();
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/ArrayAnnotation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/ArrayAnnotation.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/ArrayAnnotation.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/ArrayAnnotation.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.model.literal.types;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * User: guillaume
+ * Date: 09/07/13
+ * Time: 10:15
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ArrayAnnotation {
+ String[] arrayOfString();
+ Class<?>[] arrayOfClass();
+ Mode[] arrayOfEnum();
+ InnerAnnotation[] arrayOfAnnotation();
+ Mode[] emptyArray() default {};
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/EnumAnnotation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/EnumAnnotation.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/EnumAnnotation.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/EnumAnnotation.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,38 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.model.literal.types;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * User: guillaume
+ * Date: 09/07/13
+ * Time: 10:15
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface EnumAnnotation {
+ Mode noDefault();
+ Mode withDefault() default Mode.IN;
+ Mode withDefaultOverridden() default Mode.OUT;
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/InnerAnnotation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/InnerAnnotation.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/InnerAnnotation.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/InnerAnnotation.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.model.literal.types;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * User: guillaume
+ * Date: 09/07/13
+ * Time: 10:15
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface InnerAnnotation {
+ String aString() default "42";
+ Class[] arrayOfClass() default {};
+ Mode modeEnum() default Mode.IN;
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/Mode.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/Mode.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/Mode.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/Mode.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.model.literal.types;
+
+/**
+ * User: guillaume
+ * Date: 09/07/13
+ * Time: 10:14
+ */
+public enum Mode {
+ IN, OUT
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/SimpleTypes.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/SimpleTypes.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/SimpleTypes.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/SimpleTypes.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.model.literal.types;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+* User: guillaume
+* Date: 08/07/13
+* Time: 17:37
+*/
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface SimpleTypes {
+ boolean aBoolean() default true;
+ byte aByte() default 42;
+ long aLong() default 42;
+ int anInt() default 42;
+ short aShort() default 42;
+ float aFloat() default 42;
+ double aDouble() default 42;
+ char aChar() default 'a';
+
+ String aString() default "42";
+ Class<?> aClass() default String.class;
+
+ boolean[] arrayOfBoolean() default {true, true};
+ byte[] arrayOfByte() default {42};
+ long[] arrayOfLong() default {42};
+ int[] arrayOfInt() default {42};
+ short[] arrayOfShort() default {42};
+ float[] arrayOfFloat() default 42;
+ double[] arrayOfDouble() default {};
+ char[] arrayOfChar() default {'a', 'b', 'c'};
+
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/Support.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/Support.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/Support.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/literal/types/Support.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.model.literal.types;
+
+/**
+ * User: guillaume
+ * Date: 08/07/13
+ * Time: 17:36
+ */
+@SimpleTypes
+@EnumAnnotation(
+ noDefault = Mode.IN,
+ withDefaultOverridden = Mode.IN
+)
+@ArrayAnnotation(
+ arrayOfString = {"42", "43"},
+ arrayOfEnum = Mode.IN,
+ arrayOfClass = Object.class,
+ arrayOfAnnotation = @InnerAnnotation()
+)
+@AnnotationAnnotation(
+ @InnerAnnotation(
+ arrayOfClass = Object.class
+ )
+)
+public class Support {
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/AnnotationRecorderTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/AnnotationRecorderTestCase.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/AnnotationRecorderTestCase.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/AnnotationRecorderTestCase.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,92 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.model.parser.replay;
+
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.objectweb.asm.AnnotationVisitor;
+
+import junit.framework.TestCase;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * User: guillaume
+ * Date: 30/05/13
+ * Time: 22:04
+ */
+public class AnnotationRecorderTestCase extends TestCase {
+
+ @Mock
+ private AnnotationVisitor visitor;
+
+ @Override
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ public void testVisitRecord() throws Exception {
+ AnnotationRecorder recorder = new AnnotationRecorder();
+ recorder.visit("attribute", "a value");
+ recorder.accept(visitor);
+ verify(visitor).visit("attribute", "a value");
+ }
+
+ public void testVisitEndRecord() throws Exception {
+ AnnotationRecorder recorder = new AnnotationRecorder();
+ recorder.visitEnd();
+ recorder.accept(visitor);
+ verify(visitor).visitEnd();
+ }
+
+ public void testVisitEnumRecord() throws Exception {
+ AnnotationRecorder recorder = new AnnotationRecorder();
+ recorder.visitEnum("name", "type-desc", "A");
+ recorder.accept(visitor);
+ verify(visitor).visitEnum("name", "type-desc", "A");
+ }
+
+ public void testVisitAnnotationRecord() throws Exception {
+
+ when(visitor.visitAnnotation("name", "type-desc")).thenReturn(visitor);
+
+ AnnotationRecorder recorder = new AnnotationRecorder();
+ AnnotationVisitor sub = recorder.visitAnnotation("name", "type-desc");
+ sub.visit("name2", "value2");
+ recorder.accept(visitor);
+
+ verify(visitor).visitAnnotation("name", "type-desc");
+ verify(visitor).visit("name2", "value2");
+ }
+
+ public void testVisitArrayRecord() throws Exception {
+
+ when(visitor.visitArray("name")).thenReturn(visitor);
+
+ AnnotationRecorder recorder = new AnnotationRecorder();
+ AnnotationVisitor sub = recorder.visitArray("name");
+ sub.visit("name2", "value2");
+ recorder.accept(visitor);
+
+ verify(visitor).visitArray("name");
+ verify(visitor).visit("name2", "value2");
+ }
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/CompletableBindingRegistryTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/CompletableBindingRegistryTestCase.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/CompletableBindingRegistryTestCase.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/CompletableBindingRegistryTestCase.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,83 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.registry;
+
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.objectweb.asm.Type;
+
+import junit.framework.TestCase;
+
+/**
+ * User: guillaume
+ * Date: 12/07/13
+ * Time: 10:27
+ */
+public class CompletableBindingRegistryTestCase extends TestCase {
+
+ public static final String DESCRIPTOR = "[unknown;";
+
+ @Mock
+ private BindingRegistry delegate;
+
+ @Override
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ public void testUnknownDescriptorTriggerCallback() throws Exception {
+ EmptyCompletableBindingRegistry registry = new EmptyCompletableBindingRegistry(delegate);
+ when(delegate.getBindings(DESCRIPTOR)).thenReturn(Collections.<Binding>emptyList());
+
+ registry.getBindings(DESCRIPTOR);
+
+ assertNotNull(registry.type);
+ }
+
+ public void testKnownDescriptorDoNotTriggerCallback() throws Exception {
+ EmptyCompletableBindingRegistry registry = new EmptyCompletableBindingRegistry(delegate);
+ when(delegate.getBindings(DESCRIPTOR)).thenReturn(Collections.<Binding>singletonList(new NullBinding(Type.getType(DESCRIPTOR))));
+
+ registry.getBindings(DESCRIPTOR);
+
+ assertNull(registry.type);
+ }
+
+ private static class EmptyCompletableBindingRegistry extends CompletableBindingRegistry {
+
+ public Type type = null;
+
+ public EmptyCompletableBindingRegistry(final BindingRegistry delegate) {
+ super(delegate, null);
+ }
+
+ @Override
+ protected List<Binding> createBindings(final Type type) {
+ this.type = type;
+ return Collections.emptyList();
+ }
+ }
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/DefaultBindingRegistryTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/DefaultBindingRegistryTestCase.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/DefaultBindingRegistryTestCase.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/DefaultBindingRegistryTestCase.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,82 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.registry;
+
+import junit.framework.TestCase;
+import org.apache.felix.ipojo.annotations.Provides;
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory;
+import org.apache.felix.ipojo.manipulator.spi.Predicate;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.objectweb.asm.Type;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: guillaume
+ * Date: 10/11/12
+ * Time: 10:31 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class DefaultBindingRegistryTestCase extends TestCase {
+
+ public static final Type PROVIDES_TYPE = Type.getType(Provides.class);
+ private BindingRegistry registry;
+
+ @Mock
+ private Reporter reporter;
+ @Mock
+ private AnnotationVisitorFactory factory;
+ @Mock
+ private Predicate predicate;
+
+ @Override
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ registry = new DefaultBindingRegistry(reporter);
+ }
+
+ public void testBindingAddition() throws Exception {
+ registry.addBindings(Collections.singletonList(binding()));
+
+ List<Binding> predicates = registry.getBindings(Type.getType(Provides.class).getDescriptor());
+
+ assertEquals(1, predicates.size());
+ Binding found = predicates.get(0);
+ assertNotNull(found);
+ assertEquals(predicate, found.getPredicate());
+ assertEquals(factory, found.getFactory());
+ }
+
+ public void testGetBindingsWhenEmpty() throws Exception {
+ assertTrue(registry.getBindings(PROVIDES_TYPE.getDescriptor()).isEmpty());
+ }
+
+ private Binding binding() {
+ Binding binding = new Binding();
+ binding.setAnnotationType(PROVIDES_TYPE);
+ binding.setFactory(factory);
+ binding.setPredicate(predicate);
+ return binding;
+ }
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/IgnoreAllBindingRegistryTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/IgnoreAllBindingRegistryTestCase.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/IgnoreAllBindingRegistryTestCase.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/IgnoreAllBindingRegistryTestCase.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,58 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.registry;
+
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import junit.framework.TestCase;
+
+/**
+ * User: guillaume
+ * Date: 11/07/13
+ * Time: 17:36
+ */
+public class IgnoreAllBindingRegistryTestCase extends TestCase {
+ public static final String UNKNOWN_DESCRIPTOR = "[unknown;";
+
+ @Mock
+ private BindingRegistry delegate;
+
+ @Override
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ public void testThatNullBindingIsGenerated() throws Exception {
+ when(delegate.getBindings(UNKNOWN_DESCRIPTOR)).thenReturn(Collections.<Binding>emptyList());
+
+ IgnoreAllBindingRegistry registry = new IgnoreAllBindingRegistry(delegate, null);
+
+ List<Binding> bindings = registry.getBindings(UNKNOWN_DESCRIPTOR);
+ assertTrue(bindings.get(0) instanceof NullBinding);
+
+ }
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/LegacyGenericBindingRegistryTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/LegacyGenericBindingRegistryTestCase.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/LegacyGenericBindingRegistryTestCase.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/LegacyGenericBindingRegistryTestCase.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,95 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.registry;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.objectweb.asm.Type;
+
+import junit.framework.TestCase;
+
+/**
+ * User: guillaume
+ * Date: 11/07/13
+ * Time: 17:07
+ */
+public class LegacyGenericBindingRegistryTestCase extends TestCase {
+
+ public static final String AN_IGNORED_ANNOTATION = "[an.ignored.Annotation;";
+ public static final String RECOGNISED_IPOJO_ANNOTATION = "[a.recognised.ipojo.Annotation;";
+ public static final String RECOGNISED_HANDLER_ANNOTATION = "[a.recognised.handler.Annotation;";
+
+ @Mock
+ private BindingRegistry delegate;
+
+ @Captor
+ ArgumentCaptor<List<Binding>> capture;
+
+ @Override
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ public void testNonRecognisedTypeAreIgnored() throws Exception {
+ when(delegate.getBindings(AN_IGNORED_ANNOTATION)).thenReturn(Collections.<Binding>emptyList());
+
+ LegacyGenericBindingRegistry registry = new LegacyGenericBindingRegistry(delegate, null);
+
+ List<Binding> bindings = registry.getBindings(AN_IGNORED_ANNOTATION);
+ assertTrue(bindings.isEmpty());
+
+ verify(delegate).addBindings(capture.capture());
+ assertTrue(capture.getValue().isEmpty());
+ }
+
+ public void testIPojoRecognisedTypeAreSupported() throws Exception {
+ when(delegate.getBindings(RECOGNISED_IPOJO_ANNOTATION)).thenReturn(Collections.<Binding>emptyList());
+
+ LegacyGenericBindingRegistry registry = new LegacyGenericBindingRegistry(delegate, null);
+
+ List<Binding> bindings = registry.getBindings(RECOGNISED_IPOJO_ANNOTATION);
+ assertEquals(1, bindings.size());
+
+ verify(delegate).addBindings(capture.capture());
+ Binding one = capture.getValue().get(0);
+ assertEquals(Type.getType(RECOGNISED_IPOJO_ANNOTATION), one.getAnnotationType());
+ }
+
+ public void testHandlerRecognisedTypeAreSupported() throws Exception {
+ when(delegate.getBindings(RECOGNISED_HANDLER_ANNOTATION)).thenReturn(Collections.<Binding>emptyList());
+
+ LegacyGenericBindingRegistry registry = new LegacyGenericBindingRegistry(delegate, null);
+
+ List<Binding> bindings = registry.getBindings(RECOGNISED_HANDLER_ANNOTATION);
+ assertEquals(1, bindings.size());
+
+ verify(delegate).addBindings(capture.capture());
+ Binding one = capture.getValue().get(0);
+ assertEquals(Type.getType(RECOGNISED_HANDLER_ANNOTATION), one.getAnnotationType());
+ }
+}
Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/MetaAnnotationBindingRegistryTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/MetaAnnotationBindingRegistryTestCase.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/MetaAnnotationBindingRegistryTestCase.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/MetaAnnotationBindingRegistryTestCase.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,174 @@
+/*
+ * 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.felix.ipojo.manipulator.metadata.annotation.registry;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.HandlerBinding;
+import org.apache.felix.ipojo.annotations.Ignore;
+import org.apache.felix.ipojo.annotations.Stereotype;
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.ResourceStore;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.GenericVisitorFactory;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullVisitorFactory;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype.StereotypeVisitorFactory;
+import org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory;
+import org.apache.felix.ipojo.manipulator.util.Streams;
+import org.apache.felix.ipojo.manipulator.util.Strings;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.objectweb.asm.Type;
+
+import junit.framework.TestCase;
+
+/**
+ * User: guillaume
+ * Date: 12/07/13
+ * Time: 12:13
+ */
+public class MetaAnnotationBindingRegistryTestCase extends TestCase {
+
+ public static final String DESCRIPTOR = "[unknown;";
+ public static final Type TYPE = Type.getType(DESCRIPTOR);
+
+ @Mock
+ private BindingRegistry delegate;
+
+ @Mock
+ private ResourceStore store;
+
+ @Mock
+ private Reporter reporter;
+
+ @Override
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ when(delegate.getBindings(DESCRIPTOR)).thenReturn(Collections.<Binding>emptyList());
+ }
+
+ public void testAnnotationTypeResourceNotFound() throws Exception {
+ when(store.read(anyString()))
+ .thenThrow(IOException.class);
+ MetaAnnotationBindingRegistry registry = new MetaAnnotationBindingRegistry(delegate, reporter, store);
+ assertTrue(registry.getBindings(DESCRIPTOR).isEmpty());
+ }
+
+ public void testClassicalAnnotation() throws Exception {
+ when(store.read(anyString()))
+ .thenReturn(from(Classical.class));
+ MetaAnnotationBindingRegistry registry = new MetaAnnotationBindingRegistry(delegate, reporter, store);
+ assertTrue(registry.getBindings(Type.getDescriptor(Classical.class)).isEmpty());
+ }
+
+ public void testStereotypeAnnotation() throws Exception {
+ when(store.read(anyString()))
+ .thenReturn(from(Stereotyped.class));
+ MetaAnnotationBindingRegistry registry = new MetaAnnotationBindingRegistry(delegate, reporter, store);
+ Binding binding = registry.getBindings(Type.getDescriptor(Stereotyped.class)).get(0);
+ assertTrue(binding.getFactory() instanceof StereotypeVisitorFactory);
+ }
+
+ public void testHandlerBindingAnnotation() throws Exception {
+ when(store.read(anyString()))
+ .thenReturn(from(Bound.class));
+ MetaAnnotationBindingRegistry registry = new MetaAnnotationBindingRegistry(delegate, reporter, store);
+ Binding binding = registry.getBindings(Type.getDescriptor(Bound.class)).get(0);
+ assertTrue(binding.getFactory() instanceof GenericVisitorFactory);
+ }
+
+ public void testIgnoreAnnotation() throws Exception {
+ when(store.read(anyString()))
+ .thenReturn(from(Ignored.class));
+ MetaAnnotationBindingRegistry registry = new MetaAnnotationBindingRegistry(delegate, reporter, store);
+ Binding binding = registry.getBindings(Type.getDescriptor(Ignored.class)).get(0);
+ assertTrue(binding instanceof NullBinding);
+ }
+
+ public void testBothStereotypeAndBindingAnnotation() throws Exception {
+ when(store.read(anyString()))
+ .thenReturn(from(StereotypedBinding.class));
+ MetaAnnotationBindingRegistry registry = new MetaAnnotationBindingRegistry(delegate, reporter, store);
+ List<Binding> bindings = registry.getBindings(Type.getDescriptor(StereotypedBinding.class));
+ assertEquals(2, bindings.size());
+ assertHasVisitorFactories(bindings, StereotypeVisitorFactory.class, GenericVisitorFactory.class);
+ }
+
+ public void testIgnoredWithStereotypeAnnotation() throws Exception {
+ when(store.read(anyString()))
+ .thenReturn(from(StereotypedIgnoredBinding.class));
+ MetaAnnotationBindingRegistry registry = new MetaAnnotationBindingRegistry(delegate, reporter, store);
+ List<Binding> bindings = registry.getBindings(Type.getDescriptor(StereotypedIgnoredBinding.class));
+ assertEquals(1, bindings.size());
+ assertHasVisitorFactories(bindings, NullVisitorFactory.class);
+ }
+
+ private void assertHasVisitorFactories(final List<Binding> bindings,
+ final Class<? extends AnnotationVisitorFactory>... factories) {
+ List<Class<? extends AnnotationVisitorFactory>> existing = new ArrayList<Class<? extends AnnotationVisitorFactory>>();
+ for (Binding binding : bindings) {
+ existing.add(binding.getFactory().getClass());
+ }
+
+ for (Class<? extends AnnotationVisitorFactory> factory : factories) {
+ if (!existing.remove(factory)) {
+ fail("Bindings do not contains expected AnnotationVisitorFactory type: " + factory.getName());
+ }
+ }
+ }
+
+ private byte[] from(Class<?> type) throws IOException {
+ ClassLoader loader = type.getClassLoader();
+ InputStream is = loader.getResourceAsStream(Strings.asResourcePath(type.getName()));
+ return Streams.readBytes(is);
+ }
+
+ private static @interface Classical {}
+
+ @Component
+ @Stereotype
+ private static @interface Stereotyped {}
+
+ @HandlerBinding
+ private static @interface Bound {}
+
+ @Ignore
+ private static @interface Ignored {}
+
+ @Component
+ @Stereotype
+ @HandlerBinding
+ private static @interface StereotypedBinding {}
+
+ @Component
+ @Stereotype
+ @HandlerBinding
+ @Ignore
+ private static @interface StereotypedIgnoredBinding {}
+
+}
Modified: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java?rev=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java Fri Jul 26 12:33:28 2013
@@ -22,11 +22,6 @@ package org.apache.felix.ipojo.manipulat
import junit.framework.TestCase;
import org.apache.felix.ipojo.manipulator.Reporter;
import org.apache.felix.ipojo.manipulator.ResourceStore;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.FieldGenericVisitor;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.MethodGenericVisitor;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.ParameterGenericVisitor;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.TypeGenericVisitor;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.util.Bindings;
import org.apache.felix.ipojo.manipulator.spi.AbsBindingModule;
import org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory;
import org.apache.felix.ipojo.manipulator.spi.BindingContext;
@@ -45,7 +40,6 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
@@ -73,7 +67,7 @@ public class SelectionTestCase extends T
@Override
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- registry = new BindingRegistry(reporter);
+ registry = new DefaultBindingRegistry(reporter);
when(factory.newAnnotationVisitor(any(BindingContext.class)))
.thenReturn(visitor);
// Simulate a resource not found exception
@@ -150,23 +144,6 @@ public class SelectionTestCase extends T
}
- public void testSelectionForGenericVisitors() throws Exception {
-
- assertClassSelection(OnTypeOnly.class, nullValue());
- assertFieldSelection(OnFieldOnly.class, nullValue());
- assertMethodSelection(OnMethodOnly.class, nullValue());
- assertParameterSelection(OnParameterOnly.class, nullValue());
-
- registry.getDefaultBindings().addAll(Bindings.newDefaultBindings(store, new AnnotationRegistry()));
-
- // Verifications
- assertClassSelection(OnTypeOnly.class, instanceOf(TypeGenericVisitor.class));
- assertFieldSelection(OnFieldOnly.class, instanceOf(FieldGenericVisitor.class));
- assertMethodSelection(OnMethodOnly.class, instanceOf(MethodGenericVisitor.class));
- assertParameterSelection(OnParameterOnly.class, instanceOf(ParameterGenericVisitor.class));
-
- }
-
private void assertClassSelection(Class<? extends Annotation> type, Matcher matcher) {
Selection selection = new Selection(registry, null, reporter);
selection.type(null, classNode());
Modified: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/spi/AbsBindingModuleTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/spi/AbsBindingModuleTestCase.java?rev=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/spi/AbsBindingModuleTestCase.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/spi/AbsBindingModuleTestCase.java Fri Jul 26 12:33:28 2013
@@ -20,9 +20,16 @@
package org.apache.felix.ipojo.manipulator.spi;
import junit.framework.TestCase;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.HandlerBinding;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.AnnotationLiteral;
import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.GenericVisitorFactory;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype.StereotypeVisitorFactory;
import java.lang.annotation.ElementType;
import java.util.Iterator;
@@ -30,6 +37,7 @@ import java.util.Iterator;
import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.on;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
+import static org.objectweb.asm.Type.getType;
/**
* Created with IntelliJ IDEA.
@@ -52,7 +60,7 @@ public class AbsBindingModuleTestCase ex
Iterator<Binding> i = module.iterator();
Binding one = i.next();
assertNotNull(one);
- assertEquals(Provides.class, one.getAnnotationType());
+ assertEquals(getType(Provides.class), one.getAnnotationType());
assertEquals(factory, one.getFactory());
// Only 1 Binding
@@ -72,13 +80,13 @@ public class AbsBindingModuleTestCase ex
Iterator<Binding> i = module.iterator();
Binding one = i.next();
assertNotNull(one);
- assertEquals(Provides.class, one.getAnnotationType());
+ assertEquals(getType(Provides.class), one.getAnnotationType());
assertEquals(factory, one.getFactory());
// Second Binding
Binding two = i.next();
assertNotNull(two);
- assertEquals(Requires.class, two.getAnnotationType());
+ assertEquals(getType(Requires.class), two.getAnnotationType());
assertEquals(factory, two.getFactory());
}
@@ -96,13 +104,13 @@ public class AbsBindingModuleTestCase ex
Iterator<Binding> i = module.iterator();
Binding one = i.next();
assertNotNull(one);
- assertEquals(Provides.class, one.getAnnotationType());
+ assertEquals(getType(Provides.class), one.getAnnotationType());
assertEquals(factory, one.getFactory());
// Second Binding
Binding two = i.next();
assertNotNull(two);
- assertEquals(Provides.class, two.getAnnotationType());
+ assertEquals(getType(Provides.class), two.getAnnotationType());
assertEquals(factory2, two.getFactory());
}
@@ -120,7 +128,7 @@ public class AbsBindingModuleTestCase ex
Iterator<Binding> i = module.iterator();
Binding one = i.next();
assertNotNull(one);
- assertEquals(Provides.class, one.getAnnotationType());
+ assertEquals(getType(Provides.class), one.getAnnotationType());
assertEquals(factory, one.getFactory());
// Only 1 Binding
@@ -135,8 +143,8 @@ public class AbsBindingModuleTestCase ex
bind(Provides.class)
.when(on(ElementType.FIELD))
.to(factory)
- .when(on(ElementType.PARAMETER))
- .to(factory2);
+ .when(on(ElementType.PARAMETER))
+ .to(factory2);
}
};
module.configure();
@@ -144,15 +152,111 @@ public class AbsBindingModuleTestCase ex
Iterator<Binding> i = module.iterator();
Binding one = i.next();
assertNotNull(one);
- assertEquals(Provides.class, one.getAnnotationType());
+ assertEquals(getType(Provides.class), one.getAnnotationType());
assertEquals(factory, one.getFactory());
// Second Binding
Binding two = i.next();
assertNotNull(two);
- assertEquals(Provides.class, two.getAnnotationType());
+ assertEquals(getType(Provides.class), two.getAnnotationType());
assertEquals(factory2, two.getFactory());
}
+ public void testHandlerBindings() throws Exception {
+ AbsBindingModule module = new AbsBindingModule() {
+ public void configure() {
+ bindHandlerBinding(Bound.class).to("com.acme", "foo");
+ }
+ };
+ module.configure();
+
+ Iterator<Binding> i = module.iterator();
+ Binding one = i.next();
+ assertNotNull(one);
+ assertEquals(getType(Bound.class), one.getAnnotationType());
+ assertTrue(one.getFactory() instanceof GenericVisitorFactory);
+ }
+
+ public void testStereotypeBindings() throws Exception {
+ AbsBindingModule module = new AbsBindingModule() {
+ public void configure() {
+ bindStereotype(Bound.class)
+ .with(new ComponentLiteral() {
+ @Override
+ public boolean publicFactory() {
+ return false;
+ }
+ });
+ }
+ };
+ module.configure();
+
+ Iterator<Binding> i = module.iterator();
+ Binding one = i.next();
+ assertNotNull(one);
+ assertEquals(getType(Bound.class), one.getAnnotationType());
+ assertTrue(one.getFactory() instanceof StereotypeVisitorFactory);
+ }
+
+
+ public void testIgnoreBindings() throws Exception {
+ AbsBindingModule module = new AbsBindingModule() {
+ public void configure() {
+ bindIgnore(Bound.class);
+ }
+ };
+ module.configure();
+
+ Iterator<Binding> i = module.iterator();
+ Binding one = i.next();
+ assertEquals(getType(Bound.class), one.getAnnotationType());
+ assertTrue(one instanceof NullBinding);
+ }
+
+ private static @interface Bound {}
+
+ private static class ComponentLiteral extends AnnotationLiteral<Component> implements Component {
+
+ public boolean public_factory() {
+ return true;
+ }
+
+ public boolean publicFactory() {
+ return true;
+ }
+
+ public String name() {
+ return "";
+ }
+
+ public boolean architecture() {
+ return false;
+ }
+
+ public boolean immediate() {
+ return false;
+ }
+
+ public boolean propagation() {
+ return false;
+ }
+
+ public String managedservice() {
+ return "";
+ }
+
+ public String factory_method() {
+ return "";
+ }
+
+ public String factoryMethod() {
+ return "";
+ }
+
+ public String version() {
+ return "";
+ }
+ }
+
}