|
| 1 | +/** |
| 2 | + * Copyright (C) 2011-2020 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.folo.ftest.content; |
| 17 | + |
| 18 | +import org.commonjava.indy.folo.client.IndyFoloAdminClientModule; |
| 19 | +import org.commonjava.indy.folo.client.IndyFoloContentClientModule; |
| 20 | +import org.commonjava.indy.folo.dto.TrackedContentDTO; |
| 21 | +import org.commonjava.indy.folo.dto.TrackedContentEntryDTO; |
| 22 | +import org.commonjava.indy.model.core.StoreKey; |
| 23 | +import org.junit.Test; |
| 24 | + |
| 25 | +import java.io.ByteArrayInputStream; |
| 26 | +import java.util.Set; |
| 27 | + |
| 28 | +import static org.commonjava.indy.model.core.StoreType.group; |
| 29 | +import static org.commonjava.indy.pkg.npm.model.NPMPackageTypeDescriptor.NPM_PKG_KEY; |
| 30 | +import static org.hamcrest.CoreMatchers.equalTo; |
| 31 | +import static org.hamcrest.CoreMatchers.notNullValue; |
| 32 | +import static org.junit.Assert.assertEquals; |
| 33 | +import static org.junit.Assert.assertThat; |
| 34 | + |
| 35 | +/** |
| 36 | + * <b>GIVEN:</b> |
| 37 | + * <ul> |
| 38 | + * <li>Repository(remote or group) for npm and path</li> |
| 39 | + * </ul> |
| 40 | + * |
| 41 | + * <br/> |
| 42 | + * <b>WHEN:</b> |
| 43 | + * <ul> |
| 44 | + * <li>Access path through folo track</li> |
| 45 | + * </ul> |
| 46 | + * |
| 47 | + * <br/> |
| 48 | + * <b>THEN:</b> |
| 49 | + * <ul> |
| 50 | + * <li>The path can be tracked correctly</li> |
| 51 | + * </ul> |
| 52 | + */ |
| 53 | +public class VerifyTrackedEntriesForNPMScopedPackageTest |
| 54 | + extends AbstractNPMFoloContentManagementTest |
| 55 | +{ |
| 56 | + |
| 57 | + @Test |
| 58 | + public void verifyTrackedEntryForStore() throws Exception |
| 59 | + { |
| 60 | + |
| 61 | + final String packageContent = |
| 62 | + "{\"name\": \"@babel/code-frame\",\n" + "\"description\": \"Generate errors that contain a code frame that point to source locations.\",\n" + "\"license\": \"MIT\"}"; |
| 63 | + |
| 64 | + final String packagePath = "@babel/code-frame"; |
| 65 | + |
| 66 | + final String trackingId = newName(); |
| 67 | + |
| 68 | + npmjsServer.expect( npmjsServer.formatUrl( packagePath ), 200, new ByteArrayInputStream( packageContent.getBytes() ) ); |
| 69 | + |
| 70 | + IndyFoloContentClientModule folo = client.module( IndyFoloContentClientModule.class ); |
| 71 | + |
| 72 | + final StoreKey storeKey = new StoreKey( NPM_PKG_KEY, group, PUBLIC ); |
| 73 | + |
| 74 | + folo.get( trackingId, storeKey, packagePath ); |
| 75 | + |
| 76 | + IndyFoloAdminClientModule adminModule = client.module( IndyFoloAdminClientModule.class ); |
| 77 | + boolean success = adminModule.sealTrackingRecord( trackingId ); |
| 78 | + assertThat( success, equalTo( true ) ); |
| 79 | + |
| 80 | + // check report |
| 81 | + final TrackedContentDTO report = adminModule.getTrackingReport( trackingId ); |
| 82 | + assertThat( report, notNullValue() ); |
| 83 | + |
| 84 | + final Set<TrackedContentEntryDTO> downloads = report.getDownloads(); |
| 85 | + assertThat( downloads, notNullValue() ); |
| 86 | + assertThat( downloads.size(), equalTo( 1 ) ); |
| 87 | + |
| 88 | + downloads.stream().forEach( trackedContentEntryDTO -> { |
| 89 | + assertEquals("/@babel/code-frame", trackedContentEntryDTO.getPath()); |
| 90 | + }); |
| 91 | + |
| 92 | + } |
| 93 | + |
| 94 | +} |
0 commit comments