|
| 1 | +/** |
| 2 | + * Copyright (C) 2022-2023 Red Hat, Inc. (https://github.com/Commonjava/indy-repository-service) |
| 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.service.repository.ftests.admin; |
| 17 | + |
| 18 | +import io.quarkus.test.junit.QuarkusTest; |
| 19 | +import io.quarkus.test.junit.TestProfile; |
| 20 | +import org.commonjava.indy.service.repository.ftests.AbstractStoreManagementTest; |
| 21 | +import org.commonjava.indy.service.repository.ftests.matchers.RepoEqualMatcher; |
| 22 | +import org.commonjava.indy.service.repository.ftests.profile.MemoryFunctionProfile; |
| 23 | +import org.commonjava.indy.service.repository.model.Group; |
| 24 | +import org.commonjava.indy.service.repository.model.RemoteRepository; |
| 25 | +import org.commonjava.test.http.expect.ExpectationServer; |
| 26 | +import org.commonjava.test.http.quarkus.InjectExpected; |
| 27 | +import org.junit.jupiter.api.Tag; |
| 28 | +import org.junit.jupiter.api.Test; |
| 29 | + |
| 30 | +import static io.restassured.RestAssured.given; |
| 31 | +import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; |
| 32 | +import static jakarta.ws.rs.core.Response.Status.OK; |
| 33 | +import static org.commonjava.indy.service.repository.model.pkg.MavenPackageTypeDescriptor.MAVEN_PKG_KEY; |
| 34 | +import static org.junit.Assert.assertTrue; |
| 35 | + |
| 36 | +/** |
| 37 | + * This case tests the group member add |
| 38 | + * |
| 39 | + * <br/> |
| 40 | + * <b>GIVEN:</b> |
| 41 | + * <ul> |
| 42 | + * <li>create group G repo</li> |
| 43 | + * <li>create remote M repo</li> |
| 44 | + * </ul> |
| 45 | + * |
| 46 | + * <br/> |
| 47 | + * <b>WHEN:</b> |
| 48 | + * <ul> |
| 49 | + * <li>add remote M as member into group G></li> |
| 50 | + * </ul> |
| 51 | + * |
| 52 | + * <br/> |
| 53 | + * <b>THEN:</b> |
| 54 | + * <ul> |
| 55 | + * <li>get the group G and verify the member M existence</li> |
| 56 | + * </ul> |
| 57 | + */ |
| 58 | +@QuarkusTest |
| 59 | +@TestProfile( MemoryFunctionProfile.class ) |
| 60 | +@Tag( "function" ) |
| 61 | +public class AddGroupConstituentTest |
| 62 | + extends AbstractStoreManagementTest |
| 63 | +{ |
| 64 | + |
| 65 | + @InjectExpected() |
| 66 | + public final ExpectationServer server = new ExpectationServer(); |
| 67 | + |
| 68 | + @Test |
| 69 | + public void addGroupConstituentIt() |
| 70 | + throws Exception |
| 71 | + { |
| 72 | + final String name = "G"; |
| 73 | + final Group group = new Group( MAVEN_PKG_KEY, name ); |
| 74 | + String json = mapper.writeValueAsString( group ); |
| 75 | + given().body( json ) |
| 76 | + .contentType( APPLICATION_JSON ) |
| 77 | + .post( getRepoTypeUrl( group.getKey() ) ) |
| 78 | + .then() |
| 79 | + .body( new RepoEqualMatcher<>( mapper, group, Group.class ) ); |
| 80 | + |
| 81 | + final String urlName = "urltest"; |
| 82 | + final String url = server.formatUrl( urlName ); |
| 83 | + final RemoteRepository member = new RemoteRepository( MAVEN_PKG_KEY, "M", url ); |
| 84 | + json = mapper.writeValueAsString( member ); |
| 85 | + given().body( json ) |
| 86 | + .contentType( APPLICATION_JSON ) |
| 87 | + .post( getRepoTypeUrl( member.getKey() ) ) |
| 88 | + .then() |
| 89 | + .body( new RepoEqualMatcher<>( mapper, member, RemoteRepository.class ) ); |
| 90 | + |
| 91 | + final String repoUrl = getRepoUrl( group.getKey() ); |
| 92 | + given().body( json ) |
| 93 | + .contentType( APPLICATION_JSON ) |
| 94 | + .put( repoUrl + "addConstituent" ) |
| 95 | + .then() |
| 96 | + .statusCode( OK.getStatusCode() ); |
| 97 | + |
| 98 | + String result = given().get( repoUrl ) |
| 99 | + .then() |
| 100 | + .statusCode( OK.getStatusCode() ) |
| 101 | + .body( new RepoEqualMatcher<>( mapper, group, Group.class ) ) |
| 102 | + .extract() |
| 103 | + .asString(); |
| 104 | + assertTrue( result.contains( "\"constituents\" : [ \"maven:remote:M\" ]" ) ); |
| 105 | + } |
| 106 | +} |
0 commit comments