This is an automated email from the ASF dual-hosted git repository. sseifert pushed a commit to branch feature/SLING-13050-integration-tests-single-pom in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git
commit 94a43647da4db32a22b21f56daa723698f3f8855 Author: Stefan Seifert <[email protected]> AuthorDate: Fri Jan 23 11:02:46 2026 +0100 SLING-13050 add IT test models --- pom.xml | 23 ++++++-- .../it/delegate/request/DelegateBaseModel.java | 50 ++++++++++++++++ .../it/delegate/request/DelegateExtendedModel.java | 46 +++++++++++++++ .../it/delegate/request/DelegateInterface.java | 26 +++++++++ .../models/it/delegate/request/package-info.java | 21 +++++++ .../it/delegate/resource/DelegateBaseModel.java | 44 +++++++++++++++ .../delegate/resource/DelegateExtendedModel.java | 43 ++++++++++++++ .../it/delegate/resource/DelegateInterface.java | 26 +++++++++ .../models/it/delegate/resource/package-info.java | 21 +++++++ .../models/it/delegate/viaoriginalresource/A.java | 21 +++++++ .../models/it/delegate/viaoriginalresource/A1.java | 21 +++++++ .../models/it/delegate/viaoriginalresource/B.java | 21 +++++++ .../models/it/delegate/viaoriginalresource/B1.java | 21 +++++++ .../viaoriginalresource/models/A1Impl.java | 43 ++++++++++++++ .../delegate/viaoriginalresource/models/AImpl.java | 39 +++++++++++++ .../viaoriginalresource/models/B1Impl.java | 40 +++++++++++++ .../delegate/viaoriginalresource/models/BImpl.java | 31 ++++++++++ .../viaoriginalresource/models/package-info.java | 21 +++++++ .../delegate/viaoriginalresource/package-info.java | 21 +++++++ .../implpicker/CustomLastImplementationPicker.java | 44 +++++++++++++++ .../sling/models/it/implpicker/package-info.java | 21 +++++++ .../it/models/ConstructorInjectionTestModel.java | 59 +++++++++++++++++++ .../models/it/models/FieldInjectionTestModel.java | 66 ++++++++++++++++++++++ .../it/models/InterfaceInjectionTestModel.java | 41 ++++++++++++++ .../models/it/models/JakartaRequestSelfModel.java | 26 +++++++++ .../it/models/JakartaRequestSelfModelImpl.java | 34 +++++++++++ .../models/it/models/ModelWithOptionalImport.java | 32 +++++++++++ .../sling/models/it/models/RequestSelfModel.java | 26 +++++++++ .../models/it/models/RequestSelfModelImpl.java | 34 +++++++++++ .../apache/sling/models/it/models/SelfModel.java | 34 +++++++++++ .../it/models/ServiceInjectionTestModel.java | 49 ++++++++++++++++ .../models/SlingPropertyAnnotationTestModel.java | 34 +++++++++++ .../sling/models/it/models/SourceObject.java | 34 +++++++++++ .../apache/sling/models/it/models/ViaModel.java | 36 ++++++++++++ .../implextend/ExtendsClassPropertyModel.java | 37 ++++++++++++ .../ImplementsInterfacePropertyModel.java | 53 +++++++++++++++++ .../ImplementsInterfacePropertyModel2.java | 52 +++++++++++++++++ .../InvalidImplementsInterfacePropertyModel.java | 52 +++++++++++++++++ .../implextend/InvalidSampleServiceInterface.java | 30 ++++++++++ .../models/implextend/SampleServiceInterface.java | 30 ++++++++++ .../it/models/implextend/SimplePropertyModel.java | 47 +++++++++++++++ .../models/it/models/implextend/package-info.java | 21 +++++++ .../sling/models/it/models/package-info.java | 21 +++++++ .../sling/models/it/rtbound/BaseComponent.java | 51 +++++++++++++++++ .../sling/models/it/rtbound/ExtendedComponent.java | 48 ++++++++++++++++ .../models/it/rtbound/FromRequestComponent.java | 27 +++++++++ .../sling/models/it/rtbound/package-info.java | 21 +++++++ .../models/it/rtboundpicker/BaseComponent.java | 31 ++++++++++ .../models/it/rtboundpicker/SubRTComponent.java | 31 ++++++++++ .../models/it/rtboundpicker/TestComponent.java | 24 ++++++++ .../models/it/rtboundpicker/package-info.java | 21 +++++++ .../AnotherTestBindingsValuesProvider.java | 36 ++++++++++++ .../sling/models/it/services/SimpleService.java | 23 ++++++++ .../services/SimpleServiceWithCustomRanking.java | 32 +++++++++++ .../it/services/TestBindingsValuesProvider.java | 36 ++++++++++++ .../models/it/services/TestResourceDecorator.java | 66 ++++++++++++++++++++++ .../sling/models/it/services/package-info.java | 21 +++++++ .../it/servlets/PathBoundJakartaServlet.java | 46 +++++++++++++++ .../sling/models/it/servlets/PathBoundServlet.java | 46 +++++++++++++++ .../org/apache/sling/models/it/noclasses/foo.txt | 1 + 60 files changed, 2048 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 7440647..e5d0f43 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,12 @@ <artifactId>jakarta.servlet-api</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>javax.annotation</groupId> + <artifactId>javax.annotation-api</artifactId> + <version>1.3.2</version> + <scope>provided</scope> + </dependency> <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.apache.felix.http.wrappers</artifactId> @@ -210,7 +216,7 @@ <version>2.0.0</version> <scope>test</scope> </dependency> - <!-- transitive depedendencies of org.apache.sling.servlet-helpers --> + <!-- transitive dependencies of org.apache.sling.servlet-helpers --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-collections4</artifactId> @@ -225,10 +231,16 @@ <scope>test</scope> </dependency> <dependency> - <groupId>javax.annotation</groupId> - <artifactId>javax.annotation-api</artifactId> - <version>1.3.2</version> - <scope>provided</scope> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.servlets.annotations</artifactId> + <scope>test</scope> + </dependency> + <!-- This dependency is not actually used within Sling. It's used for ModelWithOptionalImport test case to test a model with a class that is not resolved. --> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.9.4</version> + <scope>test</scope> </dependency> </dependencies> <build> @@ -290,6 +302,7 @@ <configuration> <excludes> <exclude>dependency-reduced-pom.xml</exclude> + <exclude>src/test/resources/org/apache/sling/models/it/noclasses/foo.txt</exclude> </excludes> </configuration> </plugin> diff --git a/src/test/java/org/apache/sling/models/it/delegate/request/DelegateBaseModel.java b/src/test/java/org/apache/sling/models/it/delegate/request/DelegateBaseModel.java new file mode 100644 index 0000000..1e4369e --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/request/DelegateBaseModel.java @@ -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.sling.models.it.delegate.request; + +import javax.inject.Inject; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Via; + +@Model( + adaptables = SlingHttpServletRequest.class, + adapters = DelegateInterface.class, + resourceType = "sling/delegate/base") +public class DelegateBaseModel implements DelegateInterface { + + @Inject + @Via("resource") + private String text; + + @Inject + @Via("resource") + private String other; + + @Override + public String getText() { + return text; + } + + @Override + public String getOther() { + return other; + } +} diff --git a/src/test/java/org/apache/sling/models/it/delegate/request/DelegateExtendedModel.java b/src/test/java/org/apache/sling/models/it/delegate/request/DelegateExtendedModel.java new file mode 100644 index 0000000..c2a01a7 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/request/DelegateExtendedModel.java @@ -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.sling.models.it.delegate.request; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Via; +import org.apache.sling.models.annotations.injectorspecific.Self; +import org.apache.sling.models.annotations.via.ResourceSuperType; + +@Model( + adaptables = SlingHttpServletRequest.class, + adapters = DelegateInterface.class, + resourceType = "sling/delegate/extended") +public class DelegateExtendedModel implements DelegateInterface { + + @Self + @Via(type = ResourceSuperType.class) + private DelegateInterface delegate; + + @Override + public String getOther() { + return delegate.getOther(); + } + + @Override + public String getText() { + return delegate.getText().toUpperCase(); + } +} diff --git a/src/test/java/org/apache/sling/models/it/delegate/request/DelegateInterface.java b/src/test/java/org/apache/sling/models/it/delegate/request/DelegateInterface.java new file mode 100644 index 0000000..9826052 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/request/DelegateInterface.java @@ -0,0 +1,26 @@ +/* + * 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.sling.models.it.delegate.request; + +public interface DelegateInterface { + + String getText(); + + String getOther(); +} diff --git a/src/test/java/org/apache/sling/models/it/delegate/request/package-info.java b/src/test/java/org/apache/sling/models/it/delegate/request/package-info.java new file mode 100644 index 0000000..3e7e701 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/request/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +@Version("1.0") +package org.apache.sling.models.it.delegate.request; + +import org.osgi.annotation.versioning.Version; diff --git a/src/test/java/org/apache/sling/models/it/delegate/resource/DelegateBaseModel.java b/src/test/java/org/apache/sling/models/it/delegate/resource/DelegateBaseModel.java new file mode 100644 index 0000000..0b2031b --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/resource/DelegateBaseModel.java @@ -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.sling.models.it.delegate.resource; + +import javax.inject.Inject; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; + +@Model(adaptables = Resource.class, adapters = DelegateInterface.class, resourceType = "sling/delegate/base") +public class DelegateBaseModel implements DelegateInterface { + + @Inject + private String text; + + @Inject + private String other; + + @Override + public String getText() { + return text; + } + + @Override + public String getOther() { + return other; + } +} diff --git a/src/test/java/org/apache/sling/models/it/delegate/resource/DelegateExtendedModel.java b/src/test/java/org/apache/sling/models/it/delegate/resource/DelegateExtendedModel.java new file mode 100644 index 0000000..df901f5 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/resource/DelegateExtendedModel.java @@ -0,0 +1,43 @@ +/* + * 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.sling.models.it.delegate.resource; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Via; +import org.apache.sling.models.annotations.injectorspecific.Self; +import org.apache.sling.models.annotations.via.ResourceSuperType; + +@Model(adaptables = Resource.class, adapters = DelegateInterface.class, resourceType = "sling/delegate/extended") +public class DelegateExtendedModel implements DelegateInterface { + + @Self + @Via(type = ResourceSuperType.class) + private DelegateInterface delegate; + + @Override + public String getOther() { + return delegate.getOther(); + } + + @Override + public String getText() { + return delegate.getText().toUpperCase(); + } +} diff --git a/src/test/java/org/apache/sling/models/it/delegate/resource/DelegateInterface.java b/src/test/java/org/apache/sling/models/it/delegate/resource/DelegateInterface.java new file mode 100644 index 0000000..2b208e2 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/resource/DelegateInterface.java @@ -0,0 +1,26 @@ +/* + * 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.sling.models.it.delegate.resource; + +public interface DelegateInterface { + + String getText(); + + String getOther(); +} diff --git a/src/test/java/org/apache/sling/models/it/delegate/resource/package-info.java b/src/test/java/org/apache/sling/models/it/delegate/resource/package-info.java new file mode 100644 index 0000000..a0f5c5b --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/resource/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +@Version("1.0") +package org.apache.sling.models.it.delegate.resource; + +import org.osgi.annotation.versioning.Version; diff --git a/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/A.java b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/A.java new file mode 100644 index 0000000..7581fea --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/A.java @@ -0,0 +1,21 @@ +/* + * 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.sling.models.it.delegate.viaoriginalresource; + +public interface A {} diff --git a/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/A1.java b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/A1.java new file mode 100644 index 0000000..6d3048b --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/A1.java @@ -0,0 +1,21 @@ +/* + * 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.sling.models.it.delegate.viaoriginalresource; + +public interface A1 extends A {} diff --git a/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/B.java b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/B.java new file mode 100644 index 0000000..8fbbdab --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/B.java @@ -0,0 +1,21 @@ +/* + * 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.sling.models.it.delegate.viaoriginalresource; + +public interface B {} diff --git a/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/B1.java b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/B1.java new file mode 100644 index 0000000..50fb27c --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/B1.java @@ -0,0 +1,21 @@ +/* + * 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.sling.models.it.delegate.viaoriginalresource; + +public interface B1 extends B {} diff --git a/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/A1Impl.java b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/A1Impl.java new file mode 100644 index 0000000..62e4b63 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/A1Impl.java @@ -0,0 +1,43 @@ +/* + * 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.sling.models.it.delegate.viaoriginalresource.models; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Via; +import org.apache.sling.models.annotations.injectorspecific.Self; +import org.apache.sling.models.annotations.via.ResourceSuperType; +import org.apache.sling.models.it.delegate.viaoriginalresource.A; +import org.apache.sling.models.it.delegate.viaoriginalresource.A1; +import org.apache.sling.models.it.delegate.viaoriginalresource.B1; + +@Model( + adaptables = {SlingHttpServletRequest.class, Resource.class}, + adapters = {A1.class, A.class}, + resourceType = "delegate/nestedrtbound/specific") +public class A1Impl implements A1 { + + @Self + @Via(type = ResourceSuperType.class) + public A delegate; + + @Self + public B1 other; +} diff --git a/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/AImpl.java b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/AImpl.java new file mode 100644 index 0000000..9622bdb --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/AImpl.java @@ -0,0 +1,39 @@ +/* + * 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.sling.models.it.delegate.viaoriginalresource.models; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Via; +import org.apache.sling.models.annotations.injectorspecific.Self; +import org.apache.sling.models.annotations.via.OriginalResourceType; +import org.apache.sling.models.it.delegate.viaoriginalresource.A; +import org.apache.sling.models.it.delegate.viaoriginalresource.B; + +@Model( + adaptables = {SlingHttpServletRequest.class, Resource.class}, + adapters = {A.class}, + resourceType = "delegate/nestedrtbound/generic") +public class AImpl implements A { + + @Self + @Via(type = OriginalResourceType.class) + public B other; +} diff --git a/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/B1Impl.java b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/B1Impl.java new file mode 100644 index 0000000..85e744f --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/B1Impl.java @@ -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.sling.models.it.delegate.viaoriginalresource.models; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Via; +import org.apache.sling.models.annotations.injectorspecific.Self; +import org.apache.sling.models.annotations.via.ResourceSuperType; +import org.apache.sling.models.it.delegate.viaoriginalresource.B; +import org.apache.sling.models.it.delegate.viaoriginalresource.B1; + +@Model( + adaptables = {SlingHttpServletRequest.class, Resource.class}, + adapters = {B1.class, B.class}, + resourceType = "delegate/nestedrtbound/specific", + cache = true) +public class B1Impl implements B1 { + + @Self + @Via(type = ResourceSuperType.class) + public B delegate; +} diff --git a/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/BImpl.java b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/BImpl.java new file mode 100644 index 0000000..e3b8569 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/BImpl.java @@ -0,0 +1,31 @@ +/* + * 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.sling.models.it.delegate.viaoriginalresource.models; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.it.delegate.viaoriginalresource.B; + +@Model( + adaptables = {SlingHttpServletRequest.class, Resource.class}, + adapters = {B.class}, + resourceType = "delegate/nestedrtbound/generic", + cache = true) +public class BImpl implements B {} diff --git a/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/package-info.java b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/package-info.java new file mode 100644 index 0000000..88f82b0 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/models/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +@Version("1.0") +package org.apache.sling.models.it.delegate.viaoriginalresource.models; + +import org.osgi.annotation.versioning.Version; diff --git a/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/package-info.java b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/package-info.java new file mode 100644 index 0000000..fa049a5 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/delegate/viaoriginalresource/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +@Version("1.0") +package org.apache.sling.models.it.delegate.viaoriginalresource; + +import org.osgi.annotation.versioning.Version; diff --git a/src/test/java/org/apache/sling/models/it/implpicker/CustomLastImplementationPicker.java b/src/test/java/org/apache/sling/models/it/implpicker/CustomLastImplementationPicker.java new file mode 100644 index 0000000..5979847 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/implpicker/CustomLastImplementationPicker.java @@ -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.sling.models.it.implpicker; + +import org.apache.commons.lang3.StringUtils; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.spi.ImplementationPicker; +import org.jetbrains.annotations.NotNull; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.propertytypes.ServiceRanking; + +/** + * This is a curious {@link ImplementationPicker} implementation for integration test + * that picks the last implementation if the resource has the name "custom"; + */ +@Component(service = ImplementationPicker.class) +@ServiceRanking(100) +public class CustomLastImplementationPicker implements ImplementationPicker { + + public static final String CUSTOM_NAME = "custom"; + + public Class<?> pick(@NotNull Class<?> adapterType, Class<?>[] implementationsTypes, @NotNull Object adaptable) { + if (adaptable instanceof Resource && StringUtils.equals(((Resource) adaptable).getName(), CUSTOM_NAME)) { + return implementationsTypes[implementationsTypes.length - 1]; + } + return null; + } +} diff --git a/src/test/java/org/apache/sling/models/it/implpicker/package-info.java b/src/test/java/org/apache/sling/models/it/implpicker/package-info.java new file mode 100644 index 0000000..c8a5b3e --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/implpicker/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +@Version("1.0") +package org.apache.sling.models.it.implpicker; + +import org.osgi.annotation.versioning.Version; diff --git a/src/test/java/org/apache/sling/models/it/models/ConstructorInjectionTestModel.java b/src/test/java/org/apache/sling/models/it/models/ConstructorInjectionTestModel.java new file mode 100644 index 0000000..c80b1c5 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/ConstructorInjectionTestModel.java @@ -0,0 +1,59 @@ +/* + * 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.sling.models.it.models; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.servlet.Filter; + +import java.util.List; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.injectorspecific.Self; + +@Model(adaptables = Resource.class) +public class ConstructorInjectionTestModel { + + private final String testProperty; + private final List<Filter> filters; + private final Resource resource; + + @Inject + public ConstructorInjectionTestModel( + @Named("testProperty") String testProperty, + @Named("filters") List<Filter> filters, + @Self Resource resource) { + this.testProperty = testProperty; + this.filters = filters; + this.resource = resource; + } + + public String getTestProperty() { + return testProperty; + } + + public List<Filter> getFilters() { + return filters; + } + + public Resource getResource() { + return resource; + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/FieldInjectionTestModel.java b/src/test/java/org/apache/sling/models/it/models/FieldInjectionTestModel.java new file mode 100644 index 0000000..f8ed3a8 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/FieldInjectionTestModel.java @@ -0,0 +1,66 @@ +/* + * 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.sling.models.it.models; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.servlet.Filter; + +import java.util.List; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Optional; + +@Model(adaptables = Resource.class) +public class FieldInjectionTestModel { + + @Inject + private String testProperty; + + @Inject + @Optional + @Named("child/childProperty") + private String childProperty; + + @Inject + private List<Filter> filters; + + private final Resource resource; + + public FieldInjectionTestModel(Resource pResource) { + this.resource = pResource; + } + + public String getTestProperty() { + return testProperty; + } + + public String getChildProperty() { + return childProperty; + } + + public List<Filter> getFilters() { + return filters; + } + + public Resource getResource() { + return resource; + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/InterfaceInjectionTestModel.java b/src/test/java/org/apache/sling/models/it/models/InterfaceInjectionTestModel.java new file mode 100644 index 0000000..52e2e40 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/InterfaceInjectionTestModel.java @@ -0,0 +1,41 @@ +/* + * 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.sling.models.it.models; + +import javax.inject.Inject; +import javax.servlet.Filter; + +import java.util.List; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.injectorspecific.Self; + +@Model(adaptables = Resource.class) +public interface InterfaceInjectionTestModel { + + @Inject + String getTestProperty(); + + @Inject + List<Filter> getFilters(); + + @Self + Resource getResource(); +} diff --git a/src/test/java/org/apache/sling/models/it/models/JakartaRequestSelfModel.java b/src/test/java/org/apache/sling/models/it/models/JakartaRequestSelfModel.java new file mode 100644 index 0000000..24282af --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/JakartaRequestSelfModel.java @@ -0,0 +1,26 @@ +/* + * 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.sling.models.it.models; + +import org.apache.sling.api.SlingJakartaHttpServletRequest; + +public interface JakartaRequestSelfModel { + + SlingJakartaHttpServletRequest getRequest(); +} diff --git a/src/test/java/org/apache/sling/models/it/models/JakartaRequestSelfModelImpl.java b/src/test/java/org/apache/sling/models/it/models/JakartaRequestSelfModelImpl.java new file mode 100644 index 0000000..ab7261a --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/JakartaRequestSelfModelImpl.java @@ -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.sling.models.it.models; + +import org.apache.sling.api.SlingJakartaHttpServletRequest; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.injectorspecific.Self; + +@Model(adaptables = SlingJakartaHttpServletRequest.class, adapters = RequestSelfModel.class) +public class JakartaRequestSelfModelImpl implements JakartaRequestSelfModel { + + @Self + private SlingJakartaHttpServletRequest request; + + public SlingJakartaHttpServletRequest getRequest() { + return request; + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/ModelWithOptionalImport.java b/src/test/java/org/apache/sling/models/it/models/ModelWithOptionalImport.java new file mode 100644 index 0000000..d33b05b --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/ModelWithOptionalImport.java @@ -0,0 +1,32 @@ +/* + * 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.sling.models.it.models; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; + +@Model(adaptables = Resource.class) +public class ModelWithOptionalImport { + + // this class is not available at runtime. The containing package has an optional import so the bundle + // still resolves + @SuppressWarnings("unused") + private BeanUtils beanUtils = new BeanUtils(); +} diff --git a/src/test/java/org/apache/sling/models/it/models/RequestSelfModel.java b/src/test/java/org/apache/sling/models/it/models/RequestSelfModel.java new file mode 100644 index 0000000..b711431 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/RequestSelfModel.java @@ -0,0 +1,26 @@ +/* + * 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.sling.models.it.models; + +import org.apache.sling.api.SlingHttpServletRequest; + +public interface RequestSelfModel { + + SlingHttpServletRequest getRequest(); +} diff --git a/src/test/java/org/apache/sling/models/it/models/RequestSelfModelImpl.java b/src/test/java/org/apache/sling/models/it/models/RequestSelfModelImpl.java new file mode 100644 index 0000000..de9e83f --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/RequestSelfModelImpl.java @@ -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.sling.models.it.models; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.injectorspecific.Self; + +@Model(adaptables = SlingHttpServletRequest.class, adapters = RequestSelfModel.class) +public class RequestSelfModelImpl implements RequestSelfModel { + + @Self + private SlingHttpServletRequest request; + + public SlingHttpServletRequest getRequest() { + return request; + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/SelfModel.java b/src/test/java/org/apache/sling/models/it/models/SelfModel.java new file mode 100644 index 0000000..c635c4e --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/SelfModel.java @@ -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.sling.models.it.models; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.injectorspecific.Self; + +@Model(adaptables = Resource.class) +public class SelfModel { + + @Self + private Resource resource; + + public Resource getResource() { + return resource; + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/ServiceInjectionTestModel.java b/src/test/java/org/apache/sling/models/it/models/ServiceInjectionTestModel.java new file mode 100644 index 0000000..c9f2cf3 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/ServiceInjectionTestModel.java @@ -0,0 +1,49 @@ +/* + * 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.sling.models.it.models; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.injectorspecific.OSGiService; +import org.apache.sling.models.it.services.SimpleService; + +@Model(adaptables = Resource.class) +public class ServiceInjectionTestModel { + + @OSGiService + private SimpleService simpleService; // must return the service impl with the highest ranking + + @OSGiService + private List<SimpleService> simpleServices; + + public SimpleService getSimpleService() { + return simpleService; + } + + public Integer[] getSimpleServicesRankings() { + List<Integer> serviceRankings = new ArrayList<Integer>(); + for (SimpleService service : simpleServices) { + serviceRankings.add(service.getRanking()); + } + return serviceRankings.toArray(new Integer[serviceRankings.size()]); + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/SlingPropertyAnnotationTestModel.java b/src/test/java/org/apache/sling/models/it/models/SlingPropertyAnnotationTestModel.java new file mode 100644 index 0000000..abda77a --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/SlingPropertyAnnotationTestModel.java @@ -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.sling.models.it.models; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; + +@Model(adaptables = Resource.class) +public class SlingPropertyAnnotationTestModel { + + @ValueMapValue + private String testProperty; + + public String getTestProperty() { + return testProperty; + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/SourceObject.java b/src/test/java/org/apache/sling/models/it/models/SourceObject.java new file mode 100644 index 0000000..d31d57f --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/SourceObject.java @@ -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.sling.models.it.models; + +import org.apache.sling.api.resource.Resource; + +public class SourceObject { + + public SourceObject(Resource resource) { + this.resource = resource; + } + + private Resource resource; + + public Resource getResource() { + return resource; + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/ViaModel.java b/src/test/java/org/apache/sling/models/it/models/ViaModel.java new file mode 100644 index 0000000..a33c24e --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/ViaModel.java @@ -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.sling.models.it.models; + +import javax.inject.Inject; + +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Via; + +@Model(adaptables = SourceObject.class) +public class ViaModel { + + @Inject + @Via("resource") + private String testProperty; + + public String getTestProperty() { + return testProperty; + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/implextend/ExtendsClassPropertyModel.java b/src/test/java/org/apache/sling/models/it/models/implextend/ExtendsClassPropertyModel.java new file mode 100644 index 0000000..4dbb0dc --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/implextend/ExtendsClassPropertyModel.java @@ -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.sling.models.it.models.implextend; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; + +/** + * This is an example for a model that can not be adapted itself, but only + * to a superclass it extends. This superclass is defined as "adapters". + */ +@Model( + adaptables = Resource.class, + adapters = {SimplePropertyModel.class}) +public class ExtendsClassPropertyModel extends SimplePropertyModel { + + @Override + public String getAllProperties() { + return "!" + super.getAllProperties() + "!"; + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/implextend/ImplementsInterfacePropertyModel.java b/src/test/java/org/apache/sling/models/it/models/implextend/ImplementsInterfacePropertyModel.java new file mode 100644 index 0000000..033d184 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/implextend/ImplementsInterfacePropertyModel.java @@ -0,0 +1,53 @@ +/* + * 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.sling.models.it.models.implextend; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Optional; + +/** + * This is an example for a model that can not be adapted itself, but only + * to an interface it implements. This interfaces is defined as "adapters". + */ +@Model( + adaptables = Resource.class, + adapters = {SampleServiceInterface.class}) +public class ImplementsInterfacePropertyModel implements SampleServiceInterface { + + @Inject + private String first; + + @Inject + @Optional + private String second; + + @Inject + @Named("third") + private String thirdProperty; + + public String getAllProperties() { + StringBuilder sb = new StringBuilder(); + sb.append(first).append("|").append(second).append("|").append(thirdProperty); + return sb.toString(); + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/implextend/ImplementsInterfacePropertyModel2.java b/src/test/java/org/apache/sling/models/it/models/implextend/ImplementsInterfacePropertyModel2.java new file mode 100644 index 0000000..40d05ec --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/implextend/ImplementsInterfacePropertyModel2.java @@ -0,0 +1,52 @@ +/* + * 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.sling.models.it.models.implextend; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Optional; + +/** + * Additional model class that implements the same interface as {@link ImplementsInterfacePropertyModel}. + */ +@Model( + adaptables = Resource.class, + adapters = {SampleServiceInterface.class}) +public class ImplementsInterfacePropertyModel2 implements SampleServiceInterface { + + @Inject + private String first; + + @Inject + @Optional + private String second; + + @Inject + @Named("third") + private String thirdProperty; + + public String getAllProperties() { + StringBuilder sb = new StringBuilder(); + sb.append(first).append("|").append(second).append("|").append(thirdProperty); + return sb.toString(); + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/implextend/InvalidImplementsInterfacePropertyModel.java b/src/test/java/org/apache/sling/models/it/models/implextend/InvalidImplementsInterfacePropertyModel.java new file mode 100644 index 0000000..6f0dfdf --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/implextend/InvalidImplementsInterfacePropertyModel.java @@ -0,0 +1,52 @@ +/* + * 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.sling.models.it.models.implextend; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Optional; + +/** + * This model defines an invalid adapters property containing an interface it does not implement. + */ +@Model( + adaptables = Resource.class, + adapters = {InvalidSampleServiceInterface.class}) +public class InvalidImplementsInterfacePropertyModel implements SampleServiceInterface { + + @Inject + private String first; + + @Inject + @Optional + private String second; + + @Inject + @Named("third") + private String thirdProperty; + + public String getAllProperties() { + StringBuilder sb = new StringBuilder(); + sb.append(first).append("|").append(second).append("|").append(thirdProperty); + return sb.toString(); + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/implextend/InvalidSampleServiceInterface.java b/src/test/java/org/apache/sling/models/it/models/implextend/InvalidSampleServiceInterface.java new file mode 100644 index 0000000..18f26cb --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/implextend/InvalidSampleServiceInterface.java @@ -0,0 +1,30 @@ +/* + * 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.sling.models.it.models.implextend; + +/** + * Example "service" interface to which sling models can adapt. + */ +public interface InvalidSampleServiceInterface { + + /** + * @return concanated string with all properties + */ + String getAllProperties(); +} diff --git a/src/test/java/org/apache/sling/models/it/models/implextend/SampleServiceInterface.java b/src/test/java/org/apache/sling/models/it/models/implextend/SampleServiceInterface.java new file mode 100644 index 0000000..84f1155 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/implextend/SampleServiceInterface.java @@ -0,0 +1,30 @@ +/* + * 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.sling.models.it.models.implextend; + +/** + * Example "service" interface to which sling models can adapt. + */ +public interface SampleServiceInterface { + + /** + * @return concatenated string with all properties + */ + String getAllProperties(); +} diff --git a/src/test/java/org/apache/sling/models/it/models/implextend/SimplePropertyModel.java b/src/test/java/org/apache/sling/models/it/models/implextend/SimplePropertyModel.java new file mode 100644 index 0000000..a942c08 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/implextend/SimplePropertyModel.java @@ -0,0 +1,47 @@ +/* + * 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.sling.models.it.models.implextend; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.sling.models.annotations.Optional; + +/** + * Base class without @Model annotation. + */ +public class SimplePropertyModel { + + @Inject + private String first; + + @Inject + @Optional + private String second; + + @Inject + @Named("third") + private String thirdProperty; + + public String getAllProperties() { + StringBuilder sb = new StringBuilder(); + sb.append(first).append("|").append(second).append("|").append(thirdProperty); + return sb.toString(); + } +} diff --git a/src/test/java/org/apache/sling/models/it/models/implextend/package-info.java b/src/test/java/org/apache/sling/models/it/models/implextend/package-info.java new file mode 100644 index 0000000..3d4840c --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/implextend/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +@Version("1.0") +package org.apache.sling.models.it.models.implextend; + +import org.osgi.annotation.versioning.Version; diff --git a/src/test/java/org/apache/sling/models/it/models/package-info.java b/src/test/java/org/apache/sling/models/it/models/package-info.java new file mode 100644 index 0000000..d387b59 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/models/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +@Version("1.0") +package org.apache.sling.models.it.models; + +import org.osgi.annotation.versioning.Version; diff --git a/src/test/java/org/apache/sling/models/it/rtbound/BaseComponent.java b/src/test/java/org/apache/sling/models/it/rtbound/BaseComponent.java new file mode 100644 index 0000000..b15f9f3 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/rtbound/BaseComponent.java @@ -0,0 +1,51 @@ +/* + * 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.sling.models.it.rtbound; + +import javax.inject.Inject; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; + +@Model( + adaptables = {Resource.class}, + resourceType = "sling/rt/base") +public class BaseComponent { + + private final Resource resource; + + @Inject + private String sampleValue; + + public BaseComponent(Resource resource) { + this.resource = resource; + } + + public String getId() { + return this.resource.getPath(); + } + + public String getSampleValue() { + return sampleValue; + } + + public String getSampleValueToUpperCase() { + return sampleValue.toUpperCase(); + } +} diff --git a/src/test/java/org/apache/sling/models/it/rtbound/ExtendedComponent.java b/src/test/java/org/apache/sling/models/it/rtbound/ExtendedComponent.java new file mode 100644 index 0000000..43cbed7 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/rtbound/ExtendedComponent.java @@ -0,0 +1,48 @@ +/* + * 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.sling.models.it.rtbound; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; + +@Model( + adaptables = {Resource.class}, + resourceType = "sling/rt/extended") +public class ExtendedComponent extends BaseComponent { + + private final Date d = new Date(); + + public ExtendedComponent(Resource resource) { + super(resource); + } + + public Calendar getDateByCalendar() { + Calendar cal = new GregorianCalendar(); + cal.setTime(d); + return cal; + } + + public Date getDate() { + return d; + } +} diff --git a/src/test/java/org/apache/sling/models/it/rtbound/FromRequestComponent.java b/src/test/java/org/apache/sling/models/it/rtbound/FromRequestComponent.java new file mode 100644 index 0000000..c39b754 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/rtbound/FromRequestComponent.java @@ -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.sling.models.it.rtbound; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.models.annotations.Model; + +@Model( + adaptables = {SlingHttpServletRequest.class}, + resourceType = "sling/rt/fromRequest") +public class FromRequestComponent {} diff --git a/src/test/java/org/apache/sling/models/it/rtbound/package-info.java b/src/test/java/org/apache/sling/models/it/rtbound/package-info.java new file mode 100644 index 0000000..19332e3 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/rtbound/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +@Version("1.0") +package org.apache.sling.models.it.rtbound; + +import org.osgi.annotation.versioning.Version; diff --git a/src/test/java/org/apache/sling/models/it/rtboundpicker/BaseComponent.java b/src/test/java/org/apache/sling/models/it/rtboundpicker/BaseComponent.java new file mode 100644 index 0000000..292cef0 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/rtboundpicker/BaseComponent.java @@ -0,0 +1,31 @@ +/* + * 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.sling.models.it.rtboundpicker; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; + +@Model(adaptables = Resource.class, adapters = TestComponent.class, resourceType = "sling/rtpicker/base") +public class BaseComponent implements TestComponent { + + @Override + public String getSampleValue() { + return "base"; + } +} diff --git a/src/test/java/org/apache/sling/models/it/rtboundpicker/SubRTComponent.java b/src/test/java/org/apache/sling/models/it/rtboundpicker/SubRTComponent.java new file mode 100644 index 0000000..32011b2 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/rtboundpicker/SubRTComponent.java @@ -0,0 +1,31 @@ +/* + * 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.sling.models.it.rtboundpicker; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; + +@Model(adaptables = Resource.class, adapters = TestComponent.class, resourceType = "sling/rtpicker/sub") +public class SubRTComponent implements TestComponent { + + @Override + public String getSampleValue() { + return "sub"; + } +} diff --git a/src/test/java/org/apache/sling/models/it/rtboundpicker/TestComponent.java b/src/test/java/org/apache/sling/models/it/rtboundpicker/TestComponent.java new file mode 100644 index 0000000..3d97aea --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/rtboundpicker/TestComponent.java @@ -0,0 +1,24 @@ +/* + * 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.sling.models.it.rtboundpicker; + +public interface TestComponent { + + String getSampleValue(); +} diff --git a/src/test/java/org/apache/sling/models/it/rtboundpicker/package-info.java b/src/test/java/org/apache/sling/models/it/rtboundpicker/package-info.java new file mode 100644 index 0000000..950815c --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/rtboundpicker/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +@Version("1.0") +package org.apache.sling.models.it.rtboundpicker; + +import org.osgi.annotation.versioning.Version; diff --git a/src/test/java/org/apache/sling/models/it/services/AnotherTestBindingsValuesProvider.java b/src/test/java/org/apache/sling/models/it/services/AnotherTestBindingsValuesProvider.java new file mode 100644 index 0000000..9dcce31 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/services/AnotherTestBindingsValuesProvider.java @@ -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.sling.models.it.services; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.osgi.service.component.annotations.Component; + +@Component( + service = Map.class, + property = {"javax.script.name=sling-models-exporter"}) +public class AnotherTestBindingsValuesProvider extends HashMap<String, Object> { + private static final long serialVersionUID = 1L; + + public AnotherTestBindingsValuesProvider() { + super.put("testBindingsObject2", Collections.singletonMap("name2", "value2")); + } +} diff --git a/src/test/java/org/apache/sling/models/it/services/SimpleService.java b/src/test/java/org/apache/sling/models/it/services/SimpleService.java new file mode 100644 index 0000000..aeb4ee1 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/services/SimpleService.java @@ -0,0 +1,23 @@ +/* + * 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.sling.models.it.services; + +public interface SimpleService { + int getRanking(); +} diff --git a/src/test/java/org/apache/sling/models/it/services/SimpleServiceWithCustomRanking.java b/src/test/java/org/apache/sling/models/it/services/SimpleServiceWithCustomRanking.java new file mode 100644 index 0000000..33a8068 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/services/SimpleServiceWithCustomRanking.java @@ -0,0 +1,32 @@ +/* + * 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.sling.models.it.services; + +public class SimpleServiceWithCustomRanking implements SimpleService { + + private final int ranking; + + public SimpleServiceWithCustomRanking(int ranking) { + this.ranking = ranking; + } + + public int getRanking() { + return ranking; + } +} diff --git a/src/test/java/org/apache/sling/models/it/services/TestBindingsValuesProvider.java b/src/test/java/org/apache/sling/models/it/services/TestBindingsValuesProvider.java new file mode 100644 index 0000000..a7dcb68 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/services/TestBindingsValuesProvider.java @@ -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.sling.models.it.services; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.osgi.service.component.annotations.Component; + +@Component( + service = Map.class, + property = {"javax.script.name=*"}) +public class TestBindingsValuesProvider extends HashMap<String, Object> { + private static final long serialVersionUID = -5029445376678233701L; + + public TestBindingsValuesProvider() { + super.put("testBindingsObject", Collections.singletonMap("name", "value")); + } +} diff --git a/src/test/java/org/apache/sling/models/it/services/TestResourceDecorator.java b/src/test/java/org/apache/sling/models/it/services/TestResourceDecorator.java new file mode 100644 index 0000000..8d2a0a1 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/services/TestResourceDecorator.java @@ -0,0 +1,66 @@ +/* + * 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.sling.models.it.services; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.sling.api.adapter.AdapterManager; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ResourceDecorator; +import org.apache.sling.api.resource.ResourceWrapper; +import org.apache.sling.api.resource.ValueMap; +import org.jetbrains.annotations.NotNull; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +@Component(service = ResourceDecorator.class) +public class TestResourceDecorator implements ResourceDecorator { + + @Reference + private AdapterManager adapterManager; + + @Override + @SuppressWarnings("null") + public Resource decorate(@NotNull Resource resource) { + ValueMap map = resource.adaptTo(ValueMap.class); + if (map != null && map.containsKey("decorate")) { + if (map.get("decorate", "default").equals("customAdaptTo")) { + return new ResourceWrapper(resource) { + @Override + public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { + AdapterType adapter = adapterManager.getAdapter(this, type); + if (adapter != null) { + return adapter; + } else { + return super.adaptTo(type); + } + } + }; + } else { + return new ResourceWrapper(resource); + } + } + return null; + } + + @Override + public Resource decorate(@NotNull Resource resource, @NotNull HttpServletRequest request) { + return decorate(resource); + } +} diff --git a/src/test/java/org/apache/sling/models/it/services/package-info.java b/src/test/java/org/apache/sling/models/it/services/package-info.java new file mode 100644 index 0000000..1f5740a --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/services/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +@Version("1.0") +package org.apache.sling.models.it.services; + +import org.osgi.annotation.versioning.Version; diff --git a/src/test/java/org/apache/sling/models/it/servlets/PathBoundJakartaServlet.java b/src/test/java/org/apache/sling/models/it/servlets/PathBoundJakartaServlet.java new file mode 100644 index 0000000..4900f29 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/servlets/PathBoundJakartaServlet.java @@ -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.sling.models.it.servlets; + +import java.io.IOException; + +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletException; +import org.apache.sling.api.SlingJakartaHttpServletRequest; +import org.apache.sling.api.SlingJakartaHttpServletResponse; +import org.apache.sling.api.servlets.SlingJakartaSafeMethodsServlet; +import org.apache.sling.models.it.models.JakartaRequestSelfModel; +import org.apache.sling.servlets.annotations.SlingServletPaths; +import org.jetbrains.annotations.NotNull; +import org.osgi.service.component.annotations.Component; + +@Component(service = Servlet.class) +@SlingServletPaths("/apps/rtpickerrequest-jakarta") +public class PathBoundJakartaServlet extends SlingJakartaSafeMethodsServlet { + private static final long serialVersionUID = 1L; + + @Override + @SuppressWarnings("unused") + protected void doGet( + @NotNull SlingJakartaHttpServletRequest request, @NotNull SlingJakartaHttpServletResponse response) + throws ServletException, IOException { + JakartaRequestSelfModel model = request.adaptTo(JakartaRequestSelfModel.class); + response.setStatus(200); + } +} diff --git a/src/test/java/org/apache/sling/models/it/servlets/PathBoundServlet.java b/src/test/java/org/apache/sling/models/it/servlets/PathBoundServlet.java new file mode 100644 index 0000000..7657275 --- /dev/null +++ b/src/test/java/org/apache/sling/models/it/servlets/PathBoundServlet.java @@ -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.sling.models.it.servlets; + +import javax.servlet.Servlet; +import javax.servlet.ServletException; + +import java.io.IOException; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.servlets.SlingSafeMethodsServlet; +import org.apache.sling.models.it.models.RequestSelfModel; +import org.apache.sling.servlets.annotations.SlingServletPaths; +import org.jetbrains.annotations.NotNull; +import org.osgi.service.component.annotations.Component; + +@Component(service = Servlet.class) +@SlingServletPaths("/apps/rtpickerrequest") +public class PathBoundServlet extends SlingSafeMethodsServlet { + private static final long serialVersionUID = 1L; + + @Override + @SuppressWarnings("unused") + protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) + throws ServletException, IOException { + RequestSelfModel model = request.adaptTo(RequestSelfModel.class); + response.setStatus(200); + } +} diff --git a/src/test/resources/org/apache/sling/models/it/noclasses/foo.txt b/src/test/resources/org/apache/sling/models/it/noclasses/foo.txt new file mode 100644 index 0000000..dd50685 --- /dev/null +++ b/src/test/resources/org/apache/sling/models/it/noclasses/foo.txt @@ -0,0 +1 @@ +text file to ensure the package gets created, but without class files \ No newline at end of file
