Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
fixing the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Kerwin committed Jul 6, 2017
1 parent 390feb9 commit 2aa864e
Show file tree
Hide file tree
Showing 13 changed files with 5,184 additions and 4,846 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.blackducksoftware.integration.hub.bdio.simple.model.DependencyNode
import com.blackducksoftware.integration.hub.bdio.simple.model.Forge
import com.blackducksoftware.integration.hub.bdio.simple.model.externalid.NameVersionExternalId
import com.blackducksoftware.integration.hub.detect.DetectConfiguration
import com.blackducksoftware.integration.hub.detect.util.FileFinder
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import com.google.gson.JsonParser
Expand All @@ -39,9 +38,6 @@ import com.google.gson.stream.JsonReader
class PackagistParser {
private Forge packagistForge = new Forge('packagist', ':')

@Autowired
FileFinder fileFinder

@Autowired
DetectConfiguration detectConfiguration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ProjectInfoGatherer {
}

//TODO: Change these methods to getProjectNameFromPath, these should be for special cases only
//TODO: Instead, this class should be deleted and these methods should be moved in to DetectProjectManager
String getProjectName(final String sourcePath) {
getProjectName(sourcePath, null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ package com.blackducksoftware.integration.hub.detect.bomtool.go
import java.nio.charset.StandardCharsets

import org.apache.commons.io.IOUtils
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.skyscreamer.jsonassert.JSONAssert
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
Expand All @@ -28,7 +26,6 @@ import com.blackducksoftware.integration.hub.bdio.simple.model.externalid.NameVe
import com.blackducksoftware.integration.hub.detect.Application
import com.blackducksoftware.integration.hub.detect.bomtool.GoDepBomTool
import com.blackducksoftware.integration.hub.detect.bomtool.go.godep.GoGodepsParser
import com.blackducksoftware.integration.hub.detect.util.ProjectInfoGatherer
import com.google.gson.Gson
import com.google.gson.GsonBuilder

Expand All @@ -38,18 +35,12 @@ import com.google.gson.GsonBuilder
public class GoGodepsParserTest {
Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create()

@Autowired
ProjectInfoGatherer projectInfoGatherer

@Test
public void goDepParserTest() throws IOException {
final GoGodepsParser goDepParser = new GoGodepsParser(gson, projectInfoGatherer)
final GoGodepsParser goDepParser = new GoGodepsParser(gson)
final String goDepOutput = IOUtils.toString(getClass().getResourceAsStream("/go/Go_Godeps.json"), StandardCharsets.UTF_8)
final DependencyNode node = goDepParser.parseGoDep(goDepOutput)
Assert.assertNotNull(node)

fixVersion(node, '1.0.0')
final String actual = gson.toJson(node)
final List<DependencyNode> projectDependencies = goDepParser.extractProjectDependencies(goDepOutput)
final String actual = gson.toJson(projectDependencies)
final String expected = IOUtils.toString(getClass().getResourceAsStream("/go/Go_GodepsParserExpected.json"), StandardCharsets.UTF_8)
JSONAssert.assertEquals(expected, actual, false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@ import org.skyscreamer.jsonassert.JSONAssert

import com.blackducksoftware.integration.hub.bdio.simple.model.DependencyNode
import com.blackducksoftware.integration.hub.detect.bomtool.go.vndr.VndrParser
import com.blackducksoftware.integration.hub.detect.util.ProjectInfoGatherer
import com.google.gson.Gson
import com.google.gson.GsonBuilder

class VndrParserTest {
Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create()

ProjectInfoGatherer projectInfoGatherer = new ProjectInfoGatherer()

@Test
public void vndrParserTest() throws IOException {
final VndrParser vndrParser = new VndrParser(projectInfoGatherer);
final VndrParser vndrParser = new VndrParser();
final String vendorConfContents = IOUtils.toString(getClass().getResourceAsStream("/go/vendor.conf"), StandardCharsets.UTF_8);
final List<DependencyNode> dependencies = vndrParser.parseVendorConf(vendorConfContents);
Assert.assertNotNull(dependencies)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,34 @@
package com.blackducksoftware.integration.hub.detect.bomtool.packagist

import static org.junit.Assert.assertTrue

import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
import org.skyscreamer.jsonassert.JSONAssert

import com.blackducksoftware.integration.hub.bdio.simple.model.DependencyNode
import com.blackducksoftware.integration.hub.detect.Application
import com.blackducksoftware.integration.hub.detect.DetectConfiguration
import com.blackducksoftware.integration.hub.detect.util.FileFinder
import com.blackducksoftware.integration.hub.detect.util.ProjectInfoGatherer
import com.blackducksoftware.integration.hub.detect.DetectProperties
import com.google.gson.Gson
import com.google.gson.GsonBuilder

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class)
@SpringBootTest
class PackagistTest {

@Autowired
FileFinder fileFinder

@Autowired
ProjectInfoGatherer projectInfoGatherer

@Autowired
DetectConfiguration detectConfiguration
public Gson gson = new GsonBuilder().setPrettyPrinting().create();

@Test
public void packagistParserTest() throws IOException {
PackagistParser testParser = new PackagistParser()
DetectProperties detectProperties = new DetectProperties()
detectProperties.packagistIncludeDevDependencies = true
DetectConfiguration detectConfiguration = new DetectConfiguration()
detectConfiguration.detectProperties = detectProperties

testParser.fileFinder = fileFinder
testParser.detectConfiguration = detectConfiguration
PackagistParser packagistParser = new PackagistParser()
packagistParser.detectConfiguration = detectConfiguration

String location = getClass().getResource("/packagist/").getFile()
def composerLockFile = new File("${location}${File.separator}composer.lock")
def composerJsonFile = new File("${location}${File.separator}composer.json")
DependencyNode actual = testParser.getDependencyNodeFromProject(composerJsonFile, composerLockFile)
def composerLockFile = new File(getClass().getResource('/packagist/composer.lock').getFile())
def composerJsonFile = new File(getClass().getResource('/packagist/composer.json').getFile())
DependencyNode dependencyNode = packagistParser.getDependencyNodeFromProject(composerJsonFile, composerLockFile)
final String actual = gson.toJson(dependencyNode);

File expected = new File(getClass().getResource("/packagist/PackagistTestDependencyNode.txt").getFile())
String expectedText = new File(getClass().getResource("/packagist/PackagistTestDependencyNode.txt").getFile()).text

assertTrue(actual.toString().contentEquals(expected.text))
JSONAssert.assertEquals(expectedText, actual, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import org.junit.Test
import org.skyscreamer.jsonassert.JSONAssert

import com.blackducksoftware.integration.hub.bdio.simple.model.DependencyNode
import com.blackducksoftware.integration.hub.bdio.simple.model.Forge
import com.blackducksoftware.integration.hub.bdio.simple.model.externalid.NameVersionExternalId
import com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNodeTransformer
import com.google.gson.Gson
import com.google.gson.GsonBuilder
Expand All @@ -21,10 +19,9 @@ class GemlockNodeParserTest {
String gemfileLockContents = getClass().getResourceAsStream('/rubygems/small_gemfile_lock').getText(StandardCharsets.UTF_8.name())
NameVersionNodeTransformer nameVersionNodeTransformer = new NameVersionNodeTransformer()
GemlockNodeParser gemlockNodeParser = new GemlockNodeParser()
DependencyNode root = new DependencyNode('testName', 'testVersion', new NameVersionExternalId(Forge.RUBYGEMS, 'testName', 'testVersion'))
gemlockNodeParser.parseProjectDependencies(nameVersionNodeTransformer, root, gemfileLockContents)
List<DependencyNode> dependencyNodes = gemlockNodeParser.parseProjectDependencies(nameVersionNodeTransformer, gemfileLockContents)

final String actual = gson.toJson(root);
final String actual = gson.toJson(dependencyNodes);
final String expected = IOUtils.toString(getClass().getResourceAsStream("/rubygems/expectedSmallParser.json"), StandardCharsets.UTF_8);
JSONAssert.assertEquals(expected, actual, false);
}
Expand All @@ -34,10 +31,9 @@ class GemlockNodeParserTest {
String gemfileLockContents = getClass().getResourceAsStream('/rubygems/Gemfile.lock').getText(StandardCharsets.UTF_8.name())
NameVersionNodeTransformer nameVersionNodeTransformer = new NameVersionNodeTransformer()
GemlockNodeParser gemlockNodeParser = new GemlockNodeParser()
DependencyNode root = new DependencyNode('testName', 'testVersion', new NameVersionExternalId(Forge.RUBYGEMS, 'testName', 'testVersion'))
gemlockNodeParser.parseProjectDependencies(nameVersionNodeTransformer, root, gemfileLockContents)
List<DependencyNode> dependencyNodes = gemlockNodeParser.parseProjectDependencies(nameVersionNodeTransformer, gemfileLockContents)

final String actual = gson.toJson(root);
final String actual = gson.toJson(dependencyNodes);
final String expected = IOUtils.toString(getClass().getResourceAsStream("/rubygems/expectedParser.json"), StandardCharsets.UTF_8);
JSONAssert.assertEquals(expected, actual, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,16 @@ import org.apache.commons.io.IOUtils
import org.json.JSONException
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.skyscreamer.jsonassert.JSONAssert
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner

import com.blackducksoftware.integration.hub.bdio.simple.model.DependencyNode
import com.blackducksoftware.integration.hub.bdio.simple.model.Forge
import com.blackducksoftware.integration.hub.bdio.simple.model.externalid.NameVersionExternalId
import com.blackducksoftware.integration.hub.detect.Application
import com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNodeTransformer
import com.blackducksoftware.integration.hub.detect.util.ProjectInfoGatherer
import com.google.gson.Gson
import com.google.gson.GsonBuilder

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class)
@SpringBootTest
class RubygemsNodePackagerTest {
Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create()

@Autowired
ProjectInfoGatherer projectInfoGatherer

@Test
public void packagerTest() throws JSONException, IOException, URISyntaxException {
final NameVersionNodeTransformer nameVersionNodeTransformer = new NameVersionNodeTransformer()
Expand All @@ -50,19 +35,13 @@ class RubygemsNodePackagerTest {
StandardCharsets.UTF_8)
final String actualText = IOUtils.toString(getClass().getResourceAsStream("/rubygems/Gemfile.lock"),
StandardCharsets.UTF_8)
final RubygemsNodePackager rubygemsNodePackager = new RubygemsNodePackager(projectInfoGatherer, nameVersionNodeTransformer)
final List<DependencyNode> projects = rubygemsNodePackager.makeDependencyNodes(sourcePath, actualText)
Assert.assertEquals(1, projects.size())

fixVersion(projects.get(0), "1.0.0")
final RubygemsNodePackager rubygemsNodePackager = new RubygemsNodePackager()
rubygemsNodePackager.nameVersionNodeTransformer = nameVersionNodeTransformer
final List<DependencyNode> projects = rubygemsNodePackager.extractProjectDependencies(actualText)
Assert.assertEquals(8, projects.size())

final String actual = gson.toJson(projects)
System.out.println(actual)
JSONAssert.assertEquals(expected, actual, false)
}

private void fixVersion(final DependencyNode node, final String newVersion) {
node.version = newVersion
node.externalId = new NameVersionExternalId(Forge.RUBYGEMS, node.name, newVersion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package com.blackducksoftware.integration.hub.detect.util;

import static org.junit.Assert.assertEquals;

import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -22,7 +21,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.blackducksoftware.integration.hub.detect.Application;
import com.blackducksoftware.integration.hub.detect.type.BomToolType;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class)
Expand All @@ -37,24 +35,6 @@ public class ProjectInfoGathererTest {
@Autowired
ProjectInfoGatherer projectInfoGatherer;

@Test
public void getProjectNameFromPath() {
final String projectName = projectInfoGatherer.getProjectName(BomToolType.MAVEN, "I/Am/A/Test/" + testName);
final String projectVersion = projectInfoGatherer.getProjectVersionName();
assertEquals(testName + "_maven", projectName);
final String aFewSecondsAfterTheValueWasCreated = DateTime.now().toString(ProjectInfoGatherer.DATE_FORMAT);

assertEquals(aFewSecondsAfterTheValueWasCreated.substring(0, 17), projectVersion.substring(0, 17));
}

@Test
public void getProjectNameFromDefault() {
final String projectName = projectInfoGatherer.getProjectName(BomToolType.MAVEN, "I/Am/A/Test/" + testName, testName2);
final String projectVersion = projectInfoGatherer.getProjectVersionName(testVersion);
assertEquals(testName2, projectName);
assertEquals(testVersion, projectVersion);
}

@Test
public void extractFinalPieceFromPath() {
assertEquals('a', projectInfoGatherer.extractFinalPieceFromSourcePath('/a'))
Expand Down

0 comments on commit 2aa864e

Please sign in to comment.