Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
NEXUS-5525: UT covering the change.
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 18, 2013
1 parent b3154a8 commit 31e4c7d
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@
*/
package org.sonatype.nexus.index.mindexer;

import static com.google.common.base.Preconditions.checkNotNull;

import java.io.File;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.apache.maven.index.artifact.ArtifactPackagingMapper;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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.index;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import java.io.File;
import java.io.FileInputStream;

import org.apache.maven.index.ArtifactInfo;
import org.apache.maven.index.IteratorSearchResponse;
import org.apache.maven.index.SearchType;
import org.junit.Test;
import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.maven.MavenHostedRepository;
import org.sonatype.nexus.proxy.maven.packaging.ArtifactPackagingMapper;
import org.sonatype.nexus.proxy.registry.RepositoryRegistry;

/**
* Custom packaging test.
*
* @author cstamas
*/
public class Nexus5525IndexerManagerTest
extends AbstractIndexerManagerTest
{
@Test
public void testDeployOfCustomPackaging()
throws Exception
{
final File jarFile = getTestFile( "src/test/resources/nexus-5525/bundle-1.0-20130318.131408-1.jar" );
final File pomFile = getTestFile( "src/test/resources/nexus-5525/bundle-1.0-20130318.131408-1.pom" );
final MavenHostedRepository snapshots =
lookup( RepositoryRegistry.class ).getRepositoryWithFacet( "snapshots", MavenHostedRepository.class );
lookup( ArtifactPackagingMapper.class ).setPropertiesFile(
getTestFile( "src/test/resources/nexus-5525/packaging2extension-mapping.properties" ) );

// simulate Maven3 deploy: it happens JAR then POM
snapshots.storeItem(
new ResourceStoreRequest( "/org/sonatype/nexus5525/bundle/1.0-SNAPSHOT/" + jarFile.getName() ),
new FileInputStream( jarFile ), null );
snapshots.storeItem(
new ResourceStoreRequest( "/org/sonatype/nexus5525/bundle/1.0-SNAPSHOT/" + pomFile.getName() ),
new FileInputStream( pomFile ), null );

wairForAsyncEventsToCalmDown();

IteratorSearchResponse response = null;
try
{
// check index
response =
lookup( IndexerManager.class ).searchArtifactIterator( "org.sonatype.nexus5525", "bundle", null,
"bundle", null, snapshots.getId(), null, null, null, false, SearchType.EXACT, null );

assertThat( response.getTotalHitsCount(), equalTo( 1 ) );
final ArtifactInfo ai = response.getResults().next();

assertThat( ai.packaging, equalTo( "bundle" ) );
assertThat( ai.fextension, equalTo( "jar" ) );
}
finally
{
if ( response != null )
{
response.close();
}
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<modelVersion>4.0.0</modelVersion>

<groupId>org.sonatype.nexus5525</groupId>
<artifactId>bundle</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>

<name>bundle Bundle</name>
<description>
bundle OSGi bundle project.
</description>

<distributionManagement>
<repository>
<id>nexus</id>
<name>Releases</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
<layout>default</layout>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>

<properties>
<maven-bundle-plugin.version>2.3.7</maven-bundle-plugin.version>
<osgi.version>4.3.1</osgi.version>
</properties>

<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>${osgi.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven-bundle-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Activator>org.sonatype.nexus5525.Activator</Bundle-Activator>
<Export-Package>
org.sonatype.nexus5525*;version=${project.version}
</Export-Package>
<Import-Package>
*
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Extra mappings

bundle=jar

0 comments on commit 31e4c7d

Please sign in to comment.