Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
323 changes: 317 additions & 6 deletions pom.xml

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions src/test/it-features/it-launcher-repoinit.txt
Original file line number Diff line number Diff line change
@@ -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.
#

create service user models-it
set ACL for models-it
allow jcr:all on /
end
30 changes: 30 additions & 0 deletions src/test/it-features/it-launcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"bundles": [
{
"id": "org.apache.sling/org.apache.sling.models.api/${models.api.version}",
"start-order": 20
},
{
"id": "org.apache.sling/org.apache.sling.models.impl/${project.version}",
"start-order": 20
},
{
"id": "org.apache.sling/org.apache.sling.models.impl/${project.version}//it-testbundle",
"start-order": 20
}
],
"configurations": {
"org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended~integration-tests": {
"user.mapping": [
"org.apache.sling.junit.core=models-it"
]
},
"org.apache.sling.commons.log.LogManager.factory.config~integration-tests": {
"org.apache.sling.commons.log.names": [
"org.apache.sling.models"
],
"org.apache.sling.commons.log.level": "${it.models.log.level}"
}
},
"repoinit:TEXT|true": "@file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.junit.teleporter.customizers;

import java.io.IOException;
import java.net.URI;
import java.util.concurrent.TimeoutException;

import org.apache.sling.junit.rules.TeleporterRule;
import org.apache.sling.models.impl.ModelAdapterFactory;
import org.apache.sling.testing.clients.ClientException;
import org.apache.sling.testing.clients.osgi.OsgiConsoleClient;
import org.apache.sling.testing.serversetup.instance.SlingTestBase;
import org.apache.sling.testing.teleporter.client.ClientSideTeleporter;
import org.apache.sling.testing.timeouts.TimeoutsProvider;

/** This is required by the TeleporterRule, to setup the client-side
* teleporter with (at least) the test server URL.
*/
public class SM_TeleporterCustomizer implements TeleporterRule.Customizer {

private static final SlingTestBase S = new SlingTestBase();

private static final Class[] EXPECTED_COMPONENTS = new Class[] {ModelAdapterFactory.class};

@Override
public void customize(TeleporterRule t, String options) {
final ClientSideTeleporter cst = (ClientSideTeleporter) t;
cst.setBaseUrl(S.getServerBaseUrl());
cst.setServerCredentials(S.getServerUsername(), S.getServerPassword());
cst.setTestReadyTimeoutSeconds(TimeoutsProvider.getInstance().getTimeout(5));
cst.includeDependencyPrefix("org.apache.sling.models.it.testing");

// additionally check for the registration of mandatory sling models components
try (OsgiConsoleClient osgiClient =
new OsgiConsoleClient(URI.create(S.getServerBaseUrl()), S.getServerUsername(), S.getServerPassword())) {
for (Class clazz : EXPECTED_COMPONENTS) {
osgiClient.waitComponentRegistered(clazz.getName(), 20000, 200);
}
} catch (ClientException | TimeoutException | InterruptedException | IOException ex) {
throw new RuntimeException("Error waiting for expected components.", ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void testFieldInjectionListsAndArrays() {
assertNotNull(model);

assertEquals(4, model.getIntList().get().size());
assertEquals(new Integer(2), model.getIntList().get().get(1));
assertEquals(Integer.valueOf(2), model.getIntList().get().get(1));

assertEquals(2, model.getStringList().get().size());
assertEquals("hello", model.getStringList().get().get(0));
Expand Down
98 changes: 98 additions & 0 deletions src/test/java/org/apache/sling/models/it/GenerateTestBundle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfo;
import io.github.classgraph.ScanResult;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.servlets.annotations.SlingServletPaths;
import org.ops4j.pax.tinybundles.TinyBundle;
import org.ops4j.pax.tinybundles.TinyBundles;
import org.osgi.framework.Constants;

/**
* This uses tinybundles to create a test bundle that is deployed to sling
* starter. The test bundle contains all classes from the packages
* org.apache.sling.models.it.testbundle.*
*/
public class GenerateTestBundle {

private static final String DUMMY_TEXT = "Dummy file for Integration Test bundle.";

public static void main(String[] args) throws Exception {
Path outputFile = Paths.get(args[0]);
try (InputStream bundleStream = createBundle().build(TinyBundles.bndBuilder())) {
Files.copy(bundleStream, outputFile);
}
System.out.println("Test bundle created at " + outputFile.toAbsolutePath());
}

static TinyBundle createBundle() {
TinyBundle bundle = TinyBundles.bundle()
.setHeader(Constants.BUNDLE_NAME, "Apache Sling Models Implementation - IT Test Bundle")
.setHeader(Constants.BUNDLE_VERSION, "1.0.0-SNAPSHOT")
.setHeader(Constants.EXPORT_PACKAGE, "org.apache.sling.models.it.testbundle.*")
// optional import for 1 test case
.setHeader(Constants.IMPORT_PACKAGE, "org.apache.commons.beanutils;resolution:=optional,*")
// add dummy files to please verify-legal-files check
.addResource("META-INF/LICENSE", new ByteArrayInputStream(DUMMY_TEXT.getBytes(StandardCharsets.UTF_8)))
.addResource("META-INF/NOTICE", new ByteArrayInputStream(DUMMY_TEXT.getBytes(StandardCharsets.UTF_8)));

// workaround to ensure Component Property Type from this annotation is applied properly
bundle.addClass(SlingServletPaths.class);

// add all testbundle classes
Set<String> modelClassNames = new TreeSet<>();
getAllClasses().forEach(clazz -> {
bundle.addClass(clazz);
if (clazz.isAnnotationPresent(Model.class)) {
modelClassNames.add(clazz.getName());
}
});

// register sling models
bundle.setHeader("Sling-Model-Classes", modelClassNames.stream().collect(Collectors.joining(",")));

return bundle;
}

/**
* Dynamically find all classes in classpath under package(s) org.apache.sling.models.it.testbundle.*
*/
static List<Class<?>> getAllClasses() {
try (ScanResult scanResult = new ClassGraph()
.enableClassInfo()
.acceptPackages("org.apache.sling.models.it.testbundle")
.scan()) {
return scanResult.getAllClasses().stream().map(ClassInfo::loadClass).collect(Collectors.toList());
}
}
}
Original file line number Diff line number Diff line change
@@ -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.testbundle.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;
}
}
Original file line number Diff line number Diff line change
@@ -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.testbundle.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();
}
}
Original file line number Diff line number Diff line change
@@ -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.testbundle.delegate.request;

public interface DelegateInterface {

String getText();

String getOther();
}
Original file line number Diff line number Diff line change
@@ -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.testbundle.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;
}
}
Loading