This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Including namespace of Coordinate in SW360Component name
Fixes #371 Creating the name of the SW360Component with the namespace and name of the Coordinate fact of the artifact using a '/' as the delimiter identical to the PURLs. The SW360ComponentAdapterUtils::createComponentName method tries to extract the component name from the ArtifactCoordinate fact first. If it doesn't exist, it extracts it from the ArtifactFilename fact. Otherwise it returns an empty string. Signed-off-by: Onur Demirci <[email protected]>
- Loading branch information
Onur Demirci
authored and
Onur Demirci
committed
Dec 18, 2019
1 parent
b18aeba
commit 52388d1
Showing
5 changed files
with
177 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
.../test/java/org/eclipse/sw360/antenna/sw360/rest/utils/SW360ComponentAdapterUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (c) Bosch Software Innovations GmbH 2019. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.sw360.antenna.sw360.rest.utils; | ||
|
||
import org.eclipse.sw360.antenna.api.exceptions.ExecutionException; | ||
import org.eclipse.sw360.antenna.model.artifact.Artifact; | ||
import org.eclipse.sw360.antenna.model.artifact.ArtifactCoordinates; | ||
import org.eclipse.sw360.antenna.model.artifact.facts.ArtifactFilename; | ||
import org.eclipse.sw360.antenna.model.coordinates.Coordinate; | ||
import org.eclipse.sw360.antenna.sw360.rest.resource.components.SW360Component; | ||
import org.eclipse.sw360.antenna.sw360.rest.resource.components.SW360ComponentType; | ||
import org.eclipse.sw360.antenna.sw360.utils.SW360ComponentAdapterUtils; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@RunWith(Parameterized.class) | ||
public class SW360ComponentAdapterUtilsTest { | ||
private Artifact artifact; | ||
private String expectedName; | ||
private SW360ComponentType expectedType; | ||
private Class<? extends Exception> expectedException; | ||
private String expectedExceptionMsg; | ||
|
||
public SW360ComponentAdapterUtilsTest(Artifact artifact, String expectedName, SW360ComponentType expectedType, | ||
Class<? extends Exception> expectedException, String expectedExceptionMsg) { | ||
this.artifact = artifact; | ||
this.expectedName = expectedName; | ||
this.expectedType = expectedType; | ||
this.expectedException = expectedException; | ||
this.expectedExceptionMsg = expectedExceptionMsg; | ||
|
||
} | ||
|
||
@Parameterized.Parameters(name = "{index}: input={0}") | ||
public static Collection<Object[]> data() { | ||
return Arrays.asList(new Object[][] { | ||
{ | ||
new Artifact() | ||
.setProprietary(true) | ||
.addFact(new ArtifactCoordinates( | ||
new Coordinate(Coordinate.Types.MAVEN, "org.example", "lib", "1.0"))), | ||
"org.example/lib", | ||
SW360ComponentType.INTERNAL, | ||
null, null | ||
}, | ||
{ | ||
new Artifact() | ||
.setProprietary(false) | ||
.addFact(new ArtifactCoordinates( | ||
new Coordinate(Coordinate.Types.NPM, "@organisation", "framework", "1.0"))), | ||
"@organisation/framework", | ||
SW360ComponentType.OSS, | ||
null, null | ||
}, | ||
{ | ||
new Artifact() | ||
.setProprietary(false) | ||
.addFact(new ArtifactCoordinates( | ||
new Coordinate(Coordinate.Types.NUGET, "Org.Example", "Library", "1.0"))), | ||
"Org.Example/Library", | ||
SW360ComponentType.OSS, | ||
null, null | ||
}, | ||
{ | ||
new Artifact() | ||
.setProprietary(false) | ||
.addFact(new ArtifactFilename("library-filename.ext")), | ||
"library-filename.ext", | ||
SW360ComponentType.OSS, | ||
null, null | ||
}, | ||
{ | ||
new Artifact() | ||
.setProprietary(false), | ||
null, | ||
SW360ComponentType.OSS, | ||
ExecutionException.class, "does not have enough facts to create a component name." | ||
} | ||
}); | ||
} | ||
|
||
@Rule | ||
public ExpectedException thrownException = ExpectedException.none(); | ||
|
||
@Test | ||
public void testCreateComponentFromArtifact() { | ||
SW360Component component = new SW360Component(); | ||
|
||
if (expectedException != null) { | ||
thrownException.expect(expectedException); | ||
thrownException.expectMessage(expectedExceptionMsg); | ||
} | ||
|
||
SW360ComponentAdapterUtils.prepareComponent(component, artifact); | ||
|
||
assertThat(component.getName()).isEqualTo(expectedName); | ||
assertThat(component.getComponentType()).isEqualTo(expectedType); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters