Search in sources :

Example 1 with DescriptorImpl

use of jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl in project nodejs-plugin by jenkinsci.

the class NPMRegistryValidatorTest method test_scopes_ok.

@Test
public void test_scopes_ok() throws Exception {
    DescriptorImpl descriptor = new DescriptorImpl();
    FormValidation result = descriptor.doCheckScopes(true, "scope1 scope2 scope3");
    assertThat(result.kind, is(Kind.OK));
}
Also used : FormValidation(hudson.util.FormValidation) DescriptorImpl(jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl) Test(org.junit.Test)

Example 2 with DescriptorImpl

use of jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl in project nodejs-plugin by jenkinsci.

the class NPMRegistryValidatorTest method test_server_url_invalid_protocol.

@Test
public void test_server_url_invalid_protocol() throws Exception {
    DescriptorImpl descriptor = new DescriptorImpl();
    FormValidation result = descriptor.doCheckUrl("hpp://acme.com/root");
    assertThat(result.kind, is(Kind.ERROR));
    assertThat(result.getMessage(), is(Messages.NPMRegistry_DescriptorImpl_invalidRegistryURL()));
}
Also used : FormValidation(hudson.util.FormValidation) DescriptorImpl(jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl) Test(org.junit.Test)

Example 3 with DescriptorImpl

use of jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl in project nodejs-plugin by jenkinsci.

the class NPMRegistryValidatorTest method test_invalid_scopes.

@Test
public void test_invalid_scopes() throws Exception {
    DescriptorImpl descriptor = new DescriptorImpl();
    FormValidation result = descriptor.doCheckScopes(true, "@");
    assertThat(result.kind, is(Kind.ERROR));
    assertThat(result.getMessage(), is(Messages.NPMRegistry_DescriptorImpl_invalidScopes()));
}
Also used : FormValidation(hudson.util.FormValidation) DescriptorImpl(jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl) Test(org.junit.Test)

Example 4 with DescriptorImpl

use of jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl in project nodejs-plugin by jenkinsci.

the class NPMRegistryValidatorTest method test_server_url_that_contains_variable.

@Test
public void test_server_url_that_contains_variable() throws Exception {
    DescriptorImpl descriptor = new DescriptorImpl();
    FormValidation result = descriptor.doCheckUrl("${REGISTRY_URL}/root");
    assertThat(result.kind, is(Kind.OK));
    result = descriptor.doCheckUrl("http://${SERVER_NAME}/root");
    assertThat(result.kind, is(Kind.OK));
    result = descriptor.doCheckUrl("http://acme.com/${CONTEXT_ROOT}");
    assertThat(result.kind, is(Kind.OK));
}
Also used : FormValidation(hudson.util.FormValidation) DescriptorImpl(jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl) Test(org.junit.Test)

Example 5 with DescriptorImpl

use of jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl in project nodejs-plugin by jenkinsci.

the class NPMRegistryValidatorTest method test_credentials_ok.

@Test
public void test_credentials_ok() throws Exception {
    String credentialsId = "secret";
    Credentials credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "", "user", "password");
    Map<Domain, List<Credentials>> credentialsMap = new HashMap<>();
    credentialsMap.put(Domain.global(), Arrays.asList(credentials));
    SystemCredentialsProvider.getInstance().setDomainCredentialsMap(credentialsMap);
    FreeStyleProject prj = mock(FreeStyleProject.class);
    when(prj.hasPermission(isA(Permission.class))).thenReturn(true);
    DescriptorImpl descriptor = mock(DescriptorImpl.class);
    when(descriptor.doCheckCredentialsId(any(Item.class), (String) any(), anyString())).thenCallRealMethod();
    String serverURL = "http://acme.com";
    FormValidation result = descriptor.doCheckCredentialsId(prj, credentialsId, serverURL);
    assertThat(result.kind, is(Kind.OK));
}
Also used : Item(hudson.model.Item) FormValidation(hudson.util.FormValidation) HashMap(java.util.HashMap) DescriptorImpl(jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl) Permission(hudson.security.Permission) List(java.util.List) UsernamePasswordCredentialsImpl(com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl) Domain(com.cloudbees.plugins.credentials.domains.Domain) FreeStyleProject(hudson.model.FreeStyleProject) Credentials(com.cloudbees.plugins.credentials.Credentials) Test(org.junit.Test)

Aggregations

FormValidation (hudson.util.FormValidation)11 DescriptorImpl (jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl)11 Test (org.junit.Test)11 FreeStyleProject (hudson.model.FreeStyleProject)3 Item (hudson.model.Item)3 Permission (hudson.security.Permission)3 Credentials (com.cloudbees.plugins.credentials.Credentials)1 Domain (com.cloudbees.plugins.credentials.domains.Domain)1 UsernamePasswordCredentialsImpl (com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl)1 HashMap (java.util.HashMap)1 List (java.util.List)1