def test_profiles(self): client = self._mock_client(COM_TEST_PROFILE_1, COM_TEST_PROJECT1) pom = Pom("com.test:profile:1.0.0", client) compile_deps = list(pom.dependencies["compile"]) assert "true" == pom.properties["active_profile"] assert compile_deps[0] == (("com.test", "project1", VR("1.0.0")), True) for input, expected in ( ("[1.5,", "true"), ("![1.5,", "false"), ("!1.5", "true"), ("1.5", "false"), ("![1.5,1.7]", "true"), ("[1.5,1.7]", "false"), ("1.8", "true"), ("!1.8", "false"), ("[1.8,)", "true"), ("![1.8,)", "false"), ("![1.5,1.8)", "true"), ("[1.5,1.8)", "false"), ("![,1.8)", "true"), ("[,1.8)", "false"), ("[,1.8]", "true"), ("![,1.8]", "false"), ): client = self._mock_client( COM_TEST_PROFILE_2.replace("@JDK@", input)) pom = Pom("com.test:profile:1.0.0", client) actual = pom.properties["default_profile"] assert expected == actual, \ "%s: Wanted %s, got %s" % (input, expected, actual)
def test_find_import_deps(self): """Test Pom._find_import_deps()""" client = self._mock_client(IMPORT_DEPS_1, FOO_PARENT_1_POM, FOO_PARENT_1_POM) pom = Pom("foo:bar:1", client) import_deps = list(pom._find_import_deps()["import"]) assert import_deps[0] == (("foo", "parent", "1"), True)
def test_find_prereqs(self): """Test Pom._find_prerequisites()""" client = self._mock_client(PREREQUISITES_1) pom = Pom("foo:bar:1", client) assert "prereq1" == pom.properties["prerequisites.one"] assert "prereq1" == pom.properties["project.prerequisites.one"] assert "prereq2" == pom.properties["prerequisites.two"] assert "prereq2" == pom.properties["project.prerequisites.two"]
def test_dependency_management(self): """Test Pom.dependency_management""" client = self._mock_client(COM_TEST_USE, COM_TEST_BOM, COM_TEST_BOM2) pom = Pom("com.test:use:1", client) dep_mgmt = pom.dependency_management assert ("1.0.0", "import", False) == dep_mgmt[("com.test", "bom")] assert ("2.0.0", "import", False) == dep_mgmt[("com.test", "bom2")] assert ("2.0.0", None, True) == dep_mgmt[("com.test", "project1")] assert ("1.0.0", None, False) == dep_mgmt[("com.test", "project2")]
def test_replace_properties(self): """Test Pom._replace_properties""" client = self._mock_client(FOO_BAR_1_POM, FOO_PARENT_1_POM) pom = Pom("foo:bar:1", client) properties = {"prop1": "\na string\n", "prop2": "${prop1}"} assert "prop1" == pom._replace_properties("prop1", properties) assert "a string" == pom._replace_properties("${prop1}", properties) assert "a string" == pom._replace_properties("${prop2}", properties) assert "baz version string" == pom._replace_properties("${bazChild}") assert "baz version string" == pom._replace_properties("${bazVersion}") assert "${unmatched}" == pom._replace_properties("${unmatched}") assert "${parentProp}" == pom.parent._replace_properties("${parentProp}") assert "resolve" == pom._replace_properties("${resolveProp}") assert "resolve" == pom._replace_properties("${parentProp}")
def test_replace_properties(self): """Test Pom._replace_properties""" client = self._mock_client(FOO_BAR_1_POM, FOO_PARENT_1_POM) pom = Pom("foo:bar:1", client) properties = { "prop1": "\na string\n", "prop2": "${prop1}", } assert "prop1" == pom._replace_properties("prop1", properties) assert "a string" == pom._replace_properties("${prop1}", properties) assert "a string" == pom._replace_properties("${prop2}", properties) assert "baz version string" == pom._replace_properties("${bazChild}") assert "baz version string" == pom._replace_properties("${bazVersion}") assert "${unmatched}" == pom._replace_properties("${unmatched}") assert "${parentProp}" == \ pom.parent._replace_properties("${parentProp}") assert "resolve" == pom._replace_properties("${resolveProp}") assert "resolve" == pom._replace_properties("${parentProp}")
def test_find_relocations(self): """Test Pom._find_relocations()""" for args, coordinate in ( ((RELOCATION_1, FOO_BAR_1_POM), "foo.org:bar:pom:1"), ((RELOCATION_2, FOO_BAR_1_POM), "foo:baz:pom:1"), ((RELOCATION_3, FOO_BAR_1_POM), "foo:bar:pom:alpha"), ((RELOCATION_4, FOO_BAR_1_POM), "foo.org:baz:pom:alpha"), ): client = self._mock_client(*args) pom = Pom(coordinate, client) assert len(pom.dependencies["relocation"]) == 1 relocations = list(pom.dependencies["relocation"]) assert relocations[0] == (("foo", "bar", VR("1")), True)
def test_deps(self): client = self._mock_client(COM_TEST_DEP, COM_TEST_PROJECT1, COM_TEST_PROJECT2) pom = Pom("com.test:dep:1.0.0", client) compile_deps = list(pom.dependencies["compile"]) runtime_deps = list(pom.dependencies["runtime"]) assert len(compile_deps) == 1 assert compile_deps[0] == (("com.test", "project1", "1.0.0"), True) assert len(runtime_deps) == 1 assert runtime_deps[0] == (("com.test", "project2", "1.0.0"), True)
def test_parent(self): """Test pom parent processing""" client = self._mock_client(FOO_PARENT_1_POM) pom = Pom.fromstring("foo:bar:1", FOO_BAR_1_POM, client) assert pom.parent.group_id == "foo" assert pom.parent.artifact_id == "parent" assert pom.parent.version == "1" assert pom.parent.properties["groupId"] == "foo" assert pom.parent.properties["artifactId"] == "parent" assert pom.parent.properties["version"] == "1" assert pom.parent.properties["project.groupId"] == "foo" assert pom.parent.properties["project.artifactId"] == "parent" assert pom.parent.properties["project.version"] == "1" assert pom.parent.properties["pom.groupId"] == "foo" assert pom.parent.properties["pom.artifactId"] == "parent" assert pom.parent.properties["pom.version"] == "1" assert pom.properties["parent.groupId"] == "foo" assert pom.properties["parent.artifactId"] == "parent" assert pom.properties["parent.version"] == "1" client.get_artifact.assert_called_with("foo:parent:pom:1")
def test_dependency_version_range(self): client = self._mock_client(COM_TEST_PROJECT3, COM_TEST_PROJECT2) client.find_artifacts.return_value = [ Artifact("com.test:project2:2.0.0"), Artifact("com.test:project2:1.0.0"), ] pom = Pom("com.test:project3:1.0.0", client) deps = list(pom.dependencies["compile"]) assert len(pom.dependencies) == 1 assert len(deps) == 1 assert deps[0] == (("com.test", "project2", "[1.0,2.0)"), True) client = self._mock_client(COM_TEST_PROJECT4) client.find_artifacts.return_value = [ Artifact("com.test:project2:2.0.0-SNAPSHOT"), Artifact("com.test:project2:1.0.0"), ] pom = Pom("com.test:project4:1.0.0", client) deps = list(pom.dependencies["compile"]) assert len(pom.dependencies) == 1 assert len(deps) == 1 assert deps[0] == (("com.test", "project2", "release"), True) client = self._mock_client( COM_TEST_PROJECT4.replace("version>release", "version>latest")) client.find_artifacts.return_value = [ Artifact("com.test:project2:2.0.0-SNAPSHOT"), Artifact("com.test:project2:1.0.0"), ] pom = Pom("com.test:project4:1.0.0", client) deps = list(pom.dependencies["compile"]) assert len(pom.dependencies) == 1 assert len(deps) == 1 assert deps[0] == (("com.test", "project2", "latest"), True) client = self._mock_client( COM_TEST_PROJECT4.replace("version>release", "version>latest.release")) client.find_artifacts.return_value = [ Artifact("com.test:project2:2.0.0-SNAPSHOT"), Artifact("com.test:project2:1.0.0"), ] pom = Pom("com.test:project4:1.0.0", client) deps = list(pom.dependencies["compile"]) assert len(pom.dependencies) == 1 assert len(deps) == 1 assert deps[0] == (("com.test", "project2", "latest.release"), True) client = self._mock_client( COM_TEST_PROJECT4.replace("version>release", "version>latest.integration")) client.find_artifacts.return_value = [ Artifact("com.test:project2:2.0.0-SNAPSHOT"), Artifact("com.test:project2:1.0.0"), ] pom = Pom("com.test:project4:1.0.0", client) deps = list(pom.dependencies["compile"]) assert len(pom.dependencies) == 1 assert len(deps) == 1 assert deps[0] == (("com.test", "project2", "latest.integration"), True)