GuvnorM2Repository { public void deployArtifact(final InputStream jarStream, final GAV gav, final boolean includeAdditionalRepositories) { deployArtifact(jarStream, gav, includeAdditionalRepositories, (repo) -> true); } GuvnorM2Repository(); @Inject  GuvnorM2Repository(ArtifactRepositoryService factory); @PostConstruct void init(); String getM2RepositoryDir(String repositoryName); String getM2RepositoryRootDir(String repositoryName); String getRepositoryURL(String repositoryName); void deployArtifact(final InputStream jarStream,
                               final GAV gav,
                               final boolean includeAdditionalRepositories); void deployArtifact(final InputStream jarStream,
                               final GAV gav,
                               final boolean includeAdditionalRepositories,
                               final Predicate<ArtifactRepository> filter); void deployPom(final InputStream pomStream,
                          final GAV gav); void deployParentPom(final GAV gav); Collection<File> listFiles(); List<File> listFiles(final String filters); List<File> listFiles(final String filters,
                                List<String> fileFormats); List<Artifact> listArtifacts(final String filters,
                                        List<String> fileFormats); String getPomText(final String path); String getKModuleText(final String path); String getKieDeploymentDescriptorText(final String path); GAV loadGAVFromJar(final String jarPath); static String loadPomFromJar(final InputStream jarInputStream); static String loadPomPropertiesFromJar(final InputStream jarInputStream); String generatePOM(final GAV gav); static String generatePomProperties(final GAV gav); String getPomXmlPath(final GAV gav); String getPomPropertiesPath(final GAV gav); String generateParentPOM(final GAV gav); boolean containsArtifact(final GAV gav); boolean containsArtifact(final GAV gav,
                                    final Predicate<ArtifactRepository> filter); File getArtifactFileFromRepository(final GAV gav);  }
@Test public void testDeployArtifactWithDeployArtifactDistributionManagement() throws Exception { final GAV gav = new GAV("org.kie.guvnor", "guvnor-m2repo-editor-backend", "0.0.1-SNAPSHOT"); final InputStream is = this.getClass().getResourceAsStream("guvnor-m2repo-editor-backend-test-with-distribution-management.jar"); repo.deployArtifact(is, gav, true); verify(repositorySystem, times(1)).deploy(any(RepositorySystemSession.class), argThat(new BaseMatcher<DeployRequest>() { @Override public void describeTo(Description description) { } @Override public boolean matches(Object item) { DeployRequest request = (DeployRequest) item; return "global-m2-repo".equals(request.getRepository().getId()); } })); verify(repositorySystem, times(1)).deploy(any(RepositorySystemSession.class), argThat(new BaseMatcher<DeployRequest>() { @Override public void describeTo(Description description) { } @Override public boolean matches(Object item) { DeployRequest request = (DeployRequest) item; String string = "example.project.http"; RemoteRepository repo = request.getRepository(); boolean equals = string.equals(repo.getId()); if (!equals) { return false; } Authentication auth = repo.getAuthentication(); Class<? extends Authentication> class1 = auth.getClass(); try { Field declaredField = class1.getDeclaredField("authentications"); declaredField.setAccessible(true); Authentication[] object = (Authentication[]) declaredField.get(auth); Authentication authentication = object[1]; Class<? extends Authentication> class2 = authentication.getClass(); boolean equals3 = "SecretAuthentication".equals(class2.getSimpleName()); if (equals3) { Field valueField = class2.getDeclaredField("value"); valueField.setAccessible(true); assertEquals("Plaintext pw (repopw) length expected.", 6, ((char[]) valueField.get(authentication)).length); } return "StringAuthentication".equals(object[0].getClass().getSimpleName()) && equals3; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } })); }
@Test public void testDeployArtifactFilteredOutAllRepositories() throws Exception { final GAV gav = new GAV("org.kie.guvnor", "guvnor-m2repo-editor-backend", "0.0.1-SNAPSHOT"); final InputStream is = this.getClass().getResourceAsStream("guvnor-m2repo-editor-backend-test-with-distribution-management.jar"); repo.deployArtifact(is, gav, true, (repo) -> false); verify(repositorySystem, never()).deploy(any(RepositorySystemSession.class), any()); }