Permalink
Browse files

Implement a new repository client

Signed-off-by: Alin Dreghiciu <adreghiciu@gmail.com>
  • Loading branch information...
adreghiciu committed Oct 30, 2012
1 parent 90b7cd0 commit b9840639e92aa90fee632244b51a5870c6af7175
Showing with 2,901 additions and 42 deletions.
  1. +40 −0 nexus/nexus-client-core-testsuite/pom.xml
  2. +35 −0 nexus/nexus-client-core-testsuite/src/test/filtered-resources/logback-test.xml
  3. +47 −0 ...client-core-testsuite/src/test/java/org/sonatype/nexus/client/testsuite/NexusClientITSupport.java
  4. +262 −0 ...nexus-client-core-testsuite/src/test/java/org/sonatype/nexus/client/testsuite/RepositoriesIT.java
  5. +2 −1 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/NexusClientException.java
  6. +2 −1 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/NexusErrorMessageException.java
  7. +3 −2 ...us-client-core/src/main/java/org/sonatype/nexus/client/core/NexusUnexpectedResponseException.java
  8. +35 −0 ...core/src/main/java/org/sonatype/nexus/client/core/spi/subsystem/repository/RepositoryFactory.java
  9. +0 −2 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/config/Segment.java
  10. +1 −0 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/content/Content.java
  11. +26 −0 ...lient-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/GroupRepository.java
  12. +36 −0 ...ient-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/HostedRepository.java
  13. +38 −0 ...lient-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/ProxyRepository.java
  14. +28 −0 ...core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/ProxyRepositoryStatus.java
  15. +35 −0 ...s-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/Repositories.java
  16. +43 −0 ...xus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/Repository.java
  17. +25 −0 ...ient-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/RepositoryStatus.java
  18. +26 −0 ...ient-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/ShadowRepository.java
  19. +26 −0 ...src/main/java/org/sonatype/nexus/client/core/subsystem/repository/maven/MavenGroupRepository.java
  20. +30 −0 ...rc/main/java/org/sonatype/nexus/client/core/subsystem/repository/maven/MavenHostedRepository.java
  21. +30 −0 ...src/main/java/org/sonatype/nexus/client/core/subsystem/repository/maven/MavenProxyRepository.java
  22. +26 −0 ...rc/main/java/org/sonatype/nexus/client/core/subsystem/repository/maven/MavenShadowRepository.java
  23. +2 −2 .../nexus-client-core/src/main/java/org/sonatype/nexus/client/internal/rest/NexusXStreamFactory.java
  24. +2 −4 ...nt-core/src/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/JerseyContent.java
  25. +108 −0 ...va/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyGroupRepository.java
  26. +61 −0 ...sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyGroupRepositoryFactory.java
  27. +98 −0 ...a/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyHostedRepository.java
  28. +64 −0 ...onatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyHostedRepositoryFactory.java
  29. +139 −0 ...va/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyProxyRepository.java
  30. +65 −0 ...sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyProxyRepositoryFactory.java
  31. +172 −0 .../java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyRepositories.java
  32. +254 −0 ...in/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyRepository.java
  33. +59 −0 ...a/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyShadowRepository.java
  34. +65 −0 ...onatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyShadowRepositoryFactory.java
  35. +50 −0 ...rg/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/ProxyRepositoryStatusImpl.java
  36. +37 −0 ...ava/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/RepositoryStatusImpl.java
  37. +45 −0 ...type/nexus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenGroupRepository.java
  38. +64 −0 ...xus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenGroupRepositoryFactory.java
  39. +61 −0 ...ype/nexus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenHostedRepository.java
  40. +63 −0 ...us/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenHostedRepositoryFactory.java
  41. +66 −0 ...type/nexus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenProxyRepository.java
  42. +64 −0 ...xus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenProxyRepositoryFactory.java
  43. +45 −0 ...ype/nexus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenShadowRepository.java
  44. +64 −0 ...us/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenShadowRepositoryFactory.java
  45. +12 −10 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/rest/jersey/JerseyNexusClient.java
  46. +10 −8 ...xus-client-core/src/main/java/org/sonatype/nexus/client/rest/jersey/JerseyNexusClientFactory.java
  47. +65 −0 ...core/src/main/java/org/sonatype/nexus/client/rest/jersey/subsystem/JerseyRepositoriesFactory.java
  48. +0 −2 ...c/main/java/org/sonatype/nexus/client/rest/jersey/subsystem/JerseyServerConfigurationFactory.java
  49. +19 −0 nexus/nexus-client-core/src/main/java/org/sonatype/plexus/rest/xstream/LookAheadStreamReader.java
  50. +87 −0 nexus/nexus-client-core/src/main/java/org/sonatype/plexus/rest/xstream/xml/LookAheadXppDriver.java
  51. +259 −0 nexus/nexus-client-core/src/main/java/org/sonatype/plexus/rest/xstream/xml/LookAheadXppReader.java
  52. +4 −10 ...client-core/src/test/java/org/sonatype/nexus/client/rest/jersey/JerseyNexusClientFactoryTest.java
  53. +1 −0 nexus/pom.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Sonatype Nexus (TM) Open Source Version
+ Copyright (c) 2007-2012 Sonatype, Inc.
+ All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+
+ This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+
+ Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ Eclipse Foundation. All other trademarks are the property of their respective owners.
+
+-->
+<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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.sonatype.nexus</groupId>
+ <artifactId>nexus</artifactId>
+ <version>2.3-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.sonatype.nexus.client</groupId>
+ <artifactId>nexus-client-core-testsuite</artifactId>
+ <name>Nexus : Client Testsuite</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.sonatype.nexus</groupId>
+ <artifactId>nexus-testsuite-support</artifactId>
+ <version>2.3-SNAPSHOT</version>
+ </dependency>
+
+ </dependencies>
+
+</project>
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Sonatype Nexus (TM) Open Source Version
+ Copyright (c) 2007-2012 Sonatype, Inc.
+ All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+
+ This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+
+ Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ Eclipse Foundation. All other trademarks are the property of their respective owners.
+
+-->
+<configuration>
+
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <target>System.out</target>
+ <encoder>
+ <pattern>%level [%thread%X{DC}] %logger - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="Sisu" level="${test.log.level.Sisu:-INFO}"/>
+ <logger name="org.apache.commons.httpclient" level="ERROR"/>
+ <logger name="org.apache.http" level="${test.log.level.org.apache.http:-DEBUG}"/>
+
+ <logger name="org.sonatype.nexus.client" level="TRACE"/>
+
+ <root level="${test.log.level:-INFO}">
+ <appender-ref ref="CONSOLE"/>
+ </root>
+
+</configuration>
@@ -0,0 +1,47 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.testsuite;
+
+import static org.sonatype.nexus.testsuite.support.ParametersLoaders.firstAvailableTestParameters;
+import static org.sonatype.nexus.testsuite.support.ParametersLoaders.systemTestParameters;
+import static org.sonatype.nexus.testsuite.support.ParametersLoaders.testParameters;
+import static org.sonatype.sisu.goodies.common.Varargs.$;
+
+import java.util.Collection;
+
+import org.junit.runners.Parameterized;
+import org.sonatype.nexus.testsuite.support.NexusRunningParametrizedITSupport;
+import org.sonatype.nexus.testsuite.support.NexusStartAndStopStrategy;
+
+@NexusStartAndStopStrategy( NexusStartAndStopStrategy.Strategy.EACH_TEST )
+public abstract class NexusClientITSupport
+ extends NexusRunningParametrizedITSupport
+{
+
+ @Parameterized.Parameters
+ public static Collection<Object[]> data()
+ {
+ return firstAvailableTestParameters(
+ systemTestParameters(),
+ testParameters(
+ $( "${it.nexus.bundle.groupId}:${it.nexus.bundle.artifactId}:zip:bundle" )
+ )
+ ).load();
+ }
+
+ public NexusClientITSupport( final String nexusBundleCoordinates )
+ {
+ super( nexusBundleCoordinates );
+ }
+
+}
@@ -0,0 +1,262 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.testsuite;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.sonatype.nexus.client.core.subsystem.repository.Repositories;
+import org.sonatype.nexus.client.core.subsystem.repository.Repository;
+import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenGroupRepository;
+import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenHostedRepository;
+import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenProxyRepository;
+import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenShadowRepository;
+
+public class RepositoriesIT
+ extends NexusClientITSupport
+{
+
+ public RepositoriesIT( final String nexusBundleCoordinates )
+ {
+ super( nexusBundleCoordinates );
+ }
+
+ @Test
+ public void getHosted()
+ {
+ final Repository repository = repositories().get( "releases" );
+ assertThat( repository, is( instanceOf( MavenHostedRepository.class ) ) );
+ }
+
+ @Test
+ public void refreshHosted()
+ {
+ final Repository repository = repositories().get( "releases" );
+ final String name = repository.name();
+ repository.withName( "foo" );
+ repository.refresh();
+ assertThat( repository.name(), is( name ) );
+ }
+
+ @Test
+ public void createHosted()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenHostedRepository.class, id )
+ .save();
+ }
+
+ @Test
+ public void removeHosted()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenHostedRepository.class, id )
+ .save()
+ .remove();
+ }
+
+ @Test
+ public void statusHosted()
+ {
+ final String id = repositoryIdForTest();
+ final MavenHostedRepository repository = repositories().create( MavenHostedRepository.class, id );
+ assertThat( repository.status().isInService(), is( false ) );
+ repository.save();
+ assertThat( repository.status().isInService(), is( true ) );
+ assertThat( repository.putOutOfService().status().isInService(), is( false ) );
+ assertThat( repository.putInService().status().isInService(), is( true ) );
+ }
+
+ @Test
+ public void getProxy()
+ {
+ final Repository repository = repositories().get( "central" );
+ assertThat( repository, is( instanceOf( MavenProxyRepository.class ) ) );
+ }
+
+ @Test
+ public void refreshProxy()
+ {
+ final Repository repository = repositories().get( "central" );
+ final String name = repository.name();
+ repository.withName( "foo" );
+ repository.refresh();
+ assertThat( repository.name(), is( name ) );
+ }
+
+ @Test
+ public void createProxy()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenProxyRepository.class, id )
+ .asProxyOf( "http://localhost:8080" )
+ .save();
+ }
+
+ public void removeProxy()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenProxyRepository.class, id )
+ .asProxyOf( "http://localhost:8080" )
+ .save()
+ .remove();
+ }
+
+ @Test
+ public void statusProxy()
+ {
+ final String id = repositoryIdForTest();
+ final MavenProxyRepository repository = repositories().create( MavenProxyRepository.class, id )
+ .asProxyOf( "http://localhost:8080" );
+ assertThat( repository.status().isInService(), is( false ) );
+ repository.save();
+ assertThat( repository.status().isInService(), is( true ) );
+ assertThat( repository.putOutOfService().status().isInService(), is( false ) );
+ assertThat( repository.putInService().status().isInService(), is( true ) );
+ }
+
+ @Test
+ public void proxyMode()
+ {
+ final String id = repositoryIdForTest();
+ final MavenProxyRepository repository = repositories().create( MavenProxyRepository.class, id )
+ .asProxyOf( "http://localhost:8080" )
+ .doNotAutoBlock();
+ assertThat( repository.status().isBlocked(), is( false ) );
+ assertThat( repository.status().isAutoBlocked(), is( false ) );
+ repository.save();
+ assertThat( repository.status().isBlocked(), is( false ) );
+ assertThat( repository.status().isAutoBlocked(), is( false ) );
+ repository.block();
+ assertThat( repository.status().isBlocked(), is( true ) );
+ assertThat( repository.status().isAutoBlocked(), is( false ) );
+ repository.unblock();
+ assertThat( repository.status().isBlocked(), is( false ) );
+ assertThat( repository.status().isAutoBlocked(), is( false ) );
+ }
+
+ @Test
+ public void getGroup()
+ {
+ final Repository repository = repositories().get( "public" );
+ assertThat( repository, is( instanceOf( MavenGroupRepository.class ) ) );
+ }
+
+ @Test
+ public void refreshGroup()
+ {
+ final Repository repository = repositories().get( "public" );
+ final String name = repository.name();
+ repository.withName( "foo" );
+ repository.refresh();
+ assertThat( repository.name(), is( name ) );
+ }
+
+ @Test
+ public void createGroup()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenGroupRepository.class, id )
+ .ofRepositories( "central", "releases", "snapshots" )
+ .save();
+ }
+
+ @Test
+ public void removeGroup()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenGroupRepository.class, id )
+ .ofRepositories( "central", "releases", "snapshots" )
+ .save();
+ }
+
+ @Test
+ public void statusGroup()
+ {
+ final String id = repositoryIdForTest();
+ final MavenGroupRepository repository = repositories().create( MavenGroupRepository.class, id )
+ .ofRepositories( "central", "releases", "snapshots" );
+ assertThat( repository.status().isInService(), is( false ) );
+ repository.save();
+ assertThat( repository.status().isInService(), is( true ) );
+ assertThat( repository.putOutOfService().status().isInService(), is( false ) );
+ assertThat( repository.putInService().status().isInService(), is( true ) );
+ }
+
+ @Test
+ public void getShadow()
+ {
+ final Repository repository = repositories().get( "central-m1" );
+ assertThat( repository, is( instanceOf( MavenShadowRepository.class ) ) );
+ }
+
+ @Test
+ public void refreshShadow()
+ {
+ final Repository repository = repositories().get( "central-m1" );
+ final String name = repository.name();
+ repository.withName( "foo" );
+ repository.refresh();
+ assertThat( repository.name(), is( name ) );
+ }
+
+ @Test
+ public void createShadow()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenShadowRepository.class, id )
+ .asShadowOf( "apache-snapshots" )
+ .save();
+ }
+
+ @Test
+ public void removeShadow()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenShadowRepository.class, id )
+ .asShadowOf( "apache-snapshots" )
+ .save()
+ .remove();
+ }
+
+ @Test
+ public void statusShadow()
+ {
+ final String id = repositoryIdForTest();
+ final MavenShadowRepository repository = repositories().create( MavenShadowRepository.class, id )
+ .asShadowOf( "apache-snapshots" );
+ assertThat( repository.status().isInService(), is( false ) );
+ repository.save();
+ assertThat( repository.status().isInService(), is( true ) );
+ assertThat( repository.putOutOfService().status().isInService(), is( false ) );
+ assertThat( repository.putInService().status().isInService(), is( true ) );
+ }
+
+ @Test
+ public void get()
+ {
+ final Collection<Repository> repositories = repositories().get();
+ assertThat( repositories.size(), is( greaterThanOrEqualTo( 7 ) ) );
+ }
+
+ private Repositories repositories()
+ {
+ return client().getSubsystem( Repositories.class );
+ }
+
+}
Oops, something went wrong.

0 comments on commit b984063

Please sign in to comment.