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 16, 2019
1 parent
6ed09be
commit c3d7f5f
Showing
2 changed files
with
97 additions
and
2 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
86 changes: 86 additions & 0 deletions
86
.../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,86 @@ | ||
/* | ||
* 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.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.Test; | ||
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; | ||
|
||
public SW360ComponentAdapterUtilsTest(Artifact artifact, String expectedName, SW360ComponentType expectedType) { | ||
this.artifact = artifact; | ||
this.expectedName = expectedName; | ||
this.expectedType = expectedType; | ||
} | ||
|
||
@Parameterized.Parameters | ||
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 | ||
}, | ||
{ | ||
new Artifact() | ||
.setProprietary(false) | ||
.addFact(new ArtifactCoordinates( | ||
new Coordinate(Coordinate.Types.NPM, "@organisation", "framework", "1.0"))), | ||
"@organisation/framework", | ||
SW360ComponentType.OSS | ||
}, | ||
{ | ||
new Artifact() | ||
.setProprietary(false) | ||
.addFact(new ArtifactCoordinates( | ||
new Coordinate(Coordinate.Types.NUGET, "Org.Example", "Library", "1.0"))), | ||
"Org.Example/Library", | ||
SW360ComponentType.OSS | ||
}, | ||
{ | ||
new Artifact() | ||
.setProprietary(false) | ||
.addFact(new ArtifactFilename("library-filename.ext")), | ||
"library-filename.ext", | ||
SW360ComponentType.OSS | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testCreateComponentFromArtifact() { | ||
SW360Component component = new SW360Component(); | ||
SW360ComponentAdapterUtils.prepareComponent(component, artifact); | ||
|
||
assertThat(component.getName()).isEqualTo(expectedName); | ||
assertThat(component.getComponentType()).isEqualTo(expectedType); | ||
} | ||
} |