This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.testing.sling-mock-jackrabbit-0.1.2 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 8230617d59189a92fc873a587db39eac74d6eb3d Author: Stefan Seifert <[email protected]> AuthorDate: Mon Oct 13 11:54:39 2014 +0000 SLING-4042 Donate sling-mock, jcr-mock, osgi-mock implementation git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/sling-mock-jackrabbit@1631356 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 95 ++++++++++++++++++++++ .../JackrabbitMockResourceResolverAdapter.java | 47 +++++++++++ .../contentimport/ContentLoaderBinaryTest.java | 55 +++++++++++++ .../contentimport/ContentLoaderJsonDamTest.java | 58 +++++++++++++ .../contentimport/ContentLoaderJsonTest.java | 58 +++++++++++++ .../resource/JcrResourceResolverTest.java | 55 +++++++++++++ .../resource/SlingCrudResourceResolverTest.java | 55 +++++++++++++ 7 files changed, 423 insertions(+) diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e3bbe73 --- /dev/null +++ b/pom.xml @@ -0,0 +1,95 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.sling</groupId> + <artifactId>sling</artifactId> + <version>22</version> + <relativePath>../../../parent/pom.xml</relativePath> + </parent> + + <artifactId>org.apache.sling.testing.sling-mock-jackrabbit</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>Apache Sling Testing Sling Mock Jackrabbit-based Resource Resolver</name> + <description>Implements a resource resolver type for Jackrabbit that can be used in unit tests based on Sling Mocks.</description> + + <properties> + <sling.java.version>6</sling.java.version> + </properties> + + <dependencies> + + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.sling-mock</artifactId> + <version>1.0.0-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.sling-mock</artifactId> + <version>1.0.0-SNAPSHOT</version> + <classifier>tests</classifier> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.commons.testing</artifactId> + <version>2.0.16</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + </exclusion> + <exclusion> + <groupId>org.jmock</groupId> + <artifactId>jmock-junit4</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>javax.jcr</groupId> + <artifactId>jcr</artifactId> + <version>2.0</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <version>1.9.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + +</project> diff --git a/src/main/java/org/apache/sling/testing/mock/sling/jackrabbit/JackrabbitMockResourceResolverAdapter.java b/src/main/java/org/apache/sling/testing/mock/sling/jackrabbit/JackrabbitMockResourceResolverAdapter.java new file mode 100644 index 0000000..601a36c --- /dev/null +++ b/src/main/java/org/apache/sling/testing/mock/sling/jackrabbit/JackrabbitMockResourceResolverAdapter.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.testing.mock.sling.jackrabbit; + +import javax.jcr.RepositoryException; + +import org.apache.sling.api.resource.ResourceResolverFactory; +import org.apache.sling.commons.testing.jcr.RepositoryProvider; +import org.apache.sling.jcr.api.SlingRepository; +import org.apache.sling.testing.mock.sling.spi.ResourceResolverTypeAdapter; + +/** + * Resource resolver type adapter for Jackrabbit repository. + */ +public class JackrabbitMockResourceResolverAdapter implements ResourceResolverTypeAdapter { + + @Override + public ResourceResolverFactory newResourceResolverFactory() { + return null; + } + + @Override + public SlingRepository newSlingRepository() { + try { + return RepositoryProvider.instance().getRepository(); + } catch (RepositoryException ex) { + throw new RuntimeException("Unable to get jackrabbit SlingRepository instance.", ex); + } + } + +} diff --git a/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderBinaryTest.java b/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderBinaryTest.java new file mode 100644 index 0000000..854209d --- /dev/null +++ b/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderBinaryTest.java @@ -0,0 +1,55 @@ +/* + * 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.testing.mock.sling.jackrabbit.contentimport; + +import java.io.IOException; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.commons.testing.jcr.RepositoryUtil; +import org.apache.sling.testing.mock.sling.MockSling; +import org.apache.sling.testing.mock.sling.ResourceResolverType; +import org.apache.sling.testing.mock.sling.loader.AbstractContentLoaderBinaryTest; + +public class ContentLoaderBinaryTest extends AbstractContentLoaderBinaryTest { + + @Override + protected ResourceResolverType getResourceResolverType() { + return ResourceResolverType.JCR_JACKRABBIT; + } + + @Override + protected ResourceResolver newResourceResolver() { + ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType()); + + // register sling node types + try { + RepositoryUtil.registerSlingNodeTypes(resolver.adaptTo(Session.class)); + } catch (IOException ex) { + throw new RuntimeException("Unable to register sling node types.", ex); + } catch (RepositoryException ex) { + throw new RuntimeException("Unable to register sling node types.", ex); + } + + return resolver; + } + +} diff --git a/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonDamTest.java b/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonDamTest.java new file mode 100644 index 0000000..b3ee20a --- /dev/null +++ b/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonDamTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.testing.mock.sling.jackrabbit.contentimport; + +import java.io.IOException; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.commons.testing.jcr.RepositoryUtil; +import org.apache.sling.testing.mock.sling.MockSling; +import org.apache.sling.testing.mock.sling.ResourceResolverType; +import org.apache.sling.testing.mock.sling.loader.AbstractContentLoaderJsonDamTest; +import org.junit.Ignore; + +//TEST IS DISABLED currently, it does not work with jackrabbit repository yet +@Ignore +public class ContentLoaderJsonDamTest extends AbstractContentLoaderJsonDamTest { + + @Override + protected ResourceResolverType getResourceResolverType() { + return ResourceResolverType.JCR_JACKRABBIT; + } + + @Override + protected ResourceResolver newResourceResolver() { + ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType()); + + // register sling node types + try { + RepositoryUtil.registerSlingNodeTypes(resolver.adaptTo(Session.class)); + } catch (IOException ex) { + throw new RuntimeException("Unable to register sling node types.", ex); + } catch (RepositoryException ex) { + throw new RuntimeException("Unable to register sling node types.", ex); + } + + return resolver; + } + +} diff --git a/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonTest.java b/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonTest.java new file mode 100644 index 0000000..9d65816 --- /dev/null +++ b/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/contentimport/ContentLoaderJsonTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.testing.mock.sling.jackrabbit.contentimport; + +import java.io.IOException; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.commons.testing.jcr.RepositoryUtil; +import org.apache.sling.testing.mock.sling.MockSling; +import org.apache.sling.testing.mock.sling.ResourceResolverType; +import org.apache.sling.testing.mock.sling.loader.AbstractContentLoaderJsonTest; +import org.junit.Ignore; + +// TEST IS DISABLED currently, it does not work with jackrabbit repository yet +@Ignore +public class ContentLoaderJsonTest extends AbstractContentLoaderJsonTest { + + @Override + protected ResourceResolverType getResourceResolverType() { + return ResourceResolverType.JCR_JACKRABBIT; + } + + @Override + protected ResourceResolver newResourceResolver() { + ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType()); + + // register sling node types + try { + RepositoryUtil.registerSlingNodeTypes(resolver.adaptTo(Session.class)); + } catch (IOException ex) { + throw new RuntimeException("Unable to register sling node types.", ex); + } catch (RepositoryException ex) { + throw new RuntimeException("Unable to register sling node types.", ex); + } + + return resolver; + } + +} diff --git a/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/JcrResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/JcrResourceResolverTest.java new file mode 100644 index 0000000..eaf27cb --- /dev/null +++ b/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/JcrResourceResolverTest.java @@ -0,0 +1,55 @@ +/* + * 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.testing.mock.sling.jackrabbit.resource; + +import java.io.IOException; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.commons.testing.jcr.RepositoryUtil; +import org.apache.sling.testing.mock.sling.MockSling; +import org.apache.sling.testing.mock.sling.ResourceResolverType; +import org.apache.sling.testing.mock.sling.resource.AbstractJcrResourceResolverTest; + +public class JcrResourceResolverTest extends AbstractJcrResourceResolverTest { + + @Override + protected ResourceResolverType getResourceResolverType() { + return ResourceResolverType.JCR_JACKRABBIT; + } + + @Override + protected ResourceResolver newResourceResolver() { + ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType()); + + // register sling node types + try { + RepositoryUtil.registerSlingNodeTypes(resolver.adaptTo(Session.class)); + } catch (IOException ex) { + throw new RuntimeException("Unable to register sling node types.", ex); + } catch (RepositoryException ex) { + throw new RuntimeException("Unable to register sling node types.", ex); + } + + return resolver; + } + +} diff --git a/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/SlingCrudResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/SlingCrudResourceResolverTest.java new file mode 100644 index 0000000..6a27396 --- /dev/null +++ b/src/test/java/org/apache/sling/testing/mock/sling/jackrabbit/resource/SlingCrudResourceResolverTest.java @@ -0,0 +1,55 @@ +/* + * 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.testing.mock.sling.jackrabbit.resource; + +import java.io.IOException; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.commons.testing.jcr.RepositoryUtil; +import org.apache.sling.testing.mock.sling.MockSling; +import org.apache.sling.testing.mock.sling.ResourceResolverType; +import org.apache.sling.testing.mock.sling.resource.AbstractSlingCrudResourceResolverTest; + +public class SlingCrudResourceResolverTest extends AbstractSlingCrudResourceResolverTest { + + @Override + protected ResourceResolverType getResourceResolverType() { + return ResourceResolverType.JCR_JACKRABBIT; + } + + @Override + protected ResourceResolver newResourceResolver() { + ResourceResolver resolver = MockSling.newResourceResolver(getResourceResolverType()); + + // register sling node types + try { + RepositoryUtil.registerSlingNodeTypes(resolver.adaptTo(Session.class)); + } catch (IOException ex) { + throw new RuntimeException("Unable to register sling node types.", ex); + } catch (RepositoryException ex) { + throw new RuntimeException("Unable to register sling node types.", ex); + } + + return resolver; + } + +} -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
