Skip to content

Commit f7606eb

Browse files
authored
Merge pull request #2064 from sswguo/npm_folo_fix
Fix the tracking path of scoped npm package
2 parents 2f3e4a1 + 33ff2e1 commit f7606eb

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
}

addons/folo/jaxrs/src/main/java/org/commonjava/indy/folo/bind/jaxrs/FoloNPMContentAccessResource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ public Response doGet( @ApiParam( "User-assigned tracking session key" ) @PathPa
226226
RequestContextHelper.setContext( CONTENT_TRACKING_ID, id );
227227

228228
final String path = Paths.get( packageName, versionTarball ).toString();
229+
230+
metadata.set( ORIGIN_PATH, path );
231+
229232
final String baseUri = getBasePath( uriInfo, id );
230233

231234
return handler.doGet( NPM_PKG_KEY, type, name, path, baseUri, request, metadata );

0 commit comments

Comments
 (0)