|
| 1 | +/** |
| 2 | + * Copyright (C) 2011-2018 Red Hat, Inc. (https://github.com/Commonjava/indy) |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.commonjava.indy.pkg.maven.content; |
| 17 | + |
| 18 | +import org.apache.commons.io.IOUtils; |
| 19 | +import org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest; |
| 20 | +import org.commonjava.indy.model.core.Group; |
| 21 | +import org.commonjava.indy.model.core.RemoteRepository; |
| 22 | +import org.commonjava.test.http.expect.ExpectationServer; |
| 23 | +import org.junit.Rule; |
| 24 | +import org.junit.Test; |
| 25 | + |
| 26 | +import java.io.InputStream; |
| 27 | + |
| 28 | +import static org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY; |
| 29 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 30 | +import static org.hamcrest.core.IsNull.notNullValue; |
| 31 | + |
| 32 | +/** |
| 33 | + * <b>GIVEN:</b> |
| 34 | + * GroupId: o.a.maven.plugins |
| 35 | + * ArtifactId: maven-antrun-plugin |
| 36 | + * |
| 37 | + * <li> |
| 38 | + * Remote repo A contains paths and content for: |
| 39 | + * |
| 40 | + * org/foo/plugins/my-plugin/1.0/my-plugin-1.0.pom |
| 41 | + * org/foo/plugins/my-plugin/maven-metadata.xml |
| 42 | + * org/foo/plugins/maven-metadata.xml |
| 43 | + * </li> |
| 44 | + * <li>Group G contains A</li> |
| 45 | + * |
| 46 | + * <br/> |
| 47 | + * <b>WHEN:</b> |
| 48 | + * <ul> |
| 49 | + * <li>Path org/foo/plugins/maven-metadata.xml is requested from A</li> |
| 50 | + * <li>Path org/foo/plugins/maven-metadata.xml is requested from G</li> |
| 51 | + * </ul> |
| 52 | + * |
| 53 | + * <br/> |
| 54 | + * <b>THEN:</b> |
| 55 | + * <ul> |
| 56 | + * <li>Indy can get plugins maven-metadata.xml from A and G</li> |
| 57 | + * </ul> |
| 58 | + */ |
| 59 | +public class GroupMetadataForRemoteTest |
| 60 | + extends AbstractIndyFunctionalTest |
| 61 | +{ |
| 62 | + @Rule |
| 63 | + public ExpectationServer server = new ExpectationServer( "repos" ); |
| 64 | + |
| 65 | + private final String REMOTE = "remote-A"; |
| 66 | + |
| 67 | + private final String GROUP = "group-G"; |
| 68 | + |
| 69 | + private final String pomPath = "org/foo/plugins/my-plugin/1.0/my-plugin-1.0.pom"; |
| 70 | + |
| 71 | + private final String metadataPath = "org/foo/plugins/my-plugin/maven-metadata.xml"; |
| 72 | + |
| 73 | + private final String metadataPluginsPath = "org/foo/plugins/maven-metadata.xml"; |
| 74 | + |
| 75 | + /* @formatter:off */ |
| 76 | + final String metadataContent = "<metadata>" |
| 77 | + + " <groupId>org.foo.plugins</groupId>" |
| 78 | + + " <artifactId>my-plugin</artifactId>" |
| 79 | + + " <versioning>" |
| 80 | + + " <latest>1.0</latest>" |
| 81 | + + " <release>1.0</release>" |
| 82 | + + " <versions>" |
| 83 | + + " <version>1.0</version>" |
| 84 | + + " </versions>" |
| 85 | + + " </versioning>" |
| 86 | + + "</metadata>"; |
| 87 | + |
| 88 | + private final String pomContent = "<project>" |
| 89 | + + " <modelVersion>4.0.0</modelVersion>" |
| 90 | + + " <groupId>org.foo.plugins</groupId>" |
| 91 | + + " <artifactId>my-plugin</artifactId>" |
| 92 | + + " <version>1.0</version>" |
| 93 | + + "</project>"; |
| 94 | + |
| 95 | + final String metadataPluginsContent = "<metadata>" |
| 96 | + + "<plugins>" |
| 97 | + + " <plugin>" |
| 98 | + + " <name>My Plugin</name>" |
| 99 | + + " <prefix>mp</prefix>" |
| 100 | + + " <artifactId>my-plugin</artifactId>" |
| 101 | + + " </plugin>" |
| 102 | + + "</plugins>" |
| 103 | + + "</metadata>"; |
| 104 | + |
| 105 | + /* @formatter:on */ |
| 106 | + |
| 107 | + @Test |
| 108 | + public void run() throws Exception |
| 109 | + { |
| 110 | + server.expect( server.formatUrl( REMOTE, pomPath ), 200, pomContent ); |
| 111 | + server.expect( server.formatUrl( REMOTE, metadataPath ), 200, metadataContent ); |
| 112 | + server.expect( server.formatUrl( REMOTE, metadataPluginsPath ), 200, metadataPluginsContent ); |
| 113 | + |
| 114 | + RemoteRepository remote1 = new RemoteRepository( MAVEN_PKG_KEY, REMOTE, server.formatUrl( REMOTE ) ); |
| 115 | + remote1 = client.stores().create( remote1, "remote A", RemoteRepository.class ); |
| 116 | + |
| 117 | + Group g = new Group( MAVEN_PKG_KEY, GROUP, remote1.getKey() ); |
| 118 | + g = client.stores().create( g, "Create group G", Group.class ); |
| 119 | + |
| 120 | + /*// Get meta from remote |
| 121 | + try (final InputStream stream = client.content().get( remote1.getKey(), metadataPluginsPath )) |
| 122 | + { |
| 123 | + assertThat( stream, notNullValue() ); |
| 124 | + String meta = IOUtils.toString( stream ); |
| 125 | + logger.debug( "Remote A meta >>>>\n" + meta ); |
| 126 | + }*/ |
| 127 | + |
| 128 | + // Get meta from group |
| 129 | + try (final InputStream stream = client.content().get( g.getKey(), metadataPluginsPath )) |
| 130 | + { |
| 131 | + assertThat( stream, notNullValue() ); |
| 132 | + String meta = IOUtils.toString( stream ); |
| 133 | + logger.debug( "Group meta >>>>\n" + meta ); |
| 134 | + } |
| 135 | + |
| 136 | + } |
| 137 | +} |
0 commit comments