DataValidator { public static void validate(final Artifact artifact) { if((artifact.getOrigin()== null || "maven".equals(artifact.getOrigin())) && (artifact.getGroupId() == null || artifact.getGroupId().isEmpty())){ throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST) .entity("Artifact groupId should not be null or empty") .build()); } if(artifact.getArtifactId() == null || artifact.getArtifactId().isEmpty()){ throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST) .entity("Artifact artifactId should not be null or empty") .build()); } if(artifact.getVersion() == null || artifact.getVersion().isEmpty()){ throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST) .entity("Artifact version should not be null or empty") .build()); } } private  DataValidator(); static void validate(final Artifact artifact); static void validatePostArtifact(final Artifact artifact); static void validate(final License license); static void validate(final Module module); static void validate(final Organization organization); static void validate(final ArtifactQuery artifactQuery);  }
@Test public void validateArtifact(){ final Artifact artifact = DataModelFactory.createArtifact("groupId", "artifactId", "version", null, null, null); WebApplicationException exception = null; try{ DataValidator.validate(artifact); } catch (WebApplicationException e){ exception = e; } assertNull(exception); }
@Test public void artifactWithGroupIdNullIsNotValid(){ final Artifact artifact = DataModelFactory.createArtifact(null, "artifactId", "version", null, null, null); WebApplicationException exception = null; try{ DataValidator.validate(artifact); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void artifactWithGroupIdEmptyIsNotValid(){ final Artifact artifact = DataModelFactory.createArtifact("", "artifactId", "version", null, null, null); WebApplicationException exception = null; try{ DataValidator.validate(artifact); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void artifactWithArtifactIdNullIsNotValid(){ final Artifact artifact = DataModelFactory.createArtifact("groupId", null, "version", null, null, null); WebApplicationException exception = null; try{ DataValidator.validate(artifact); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void artifactWithArtifactIdEmptyIsNotValid(){ final Artifact artifact = DataModelFactory.createArtifact("groupId", "", "version", null, null, null); WebApplicationException exception = null; try{ DataValidator.validate(artifact); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void artifactWithVersionNullIsNotValid(){ final Artifact artifact = DataModelFactory.createArtifact("groupId", "artifactId", null, null, null, null); WebApplicationException exception = null; try{ DataValidator.validate(artifact); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void artifactWithVersionEmptyIsNotValid(){ final Artifact artifact = DataModelFactory.createArtifact("groupId", "artifactId", "", null, null, null); WebApplicationException exception = null; try{ DataValidator.validate(artifact); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void validateLicense(){ final License license = DataModelFactory.createLicense("name", "longName", null, null, null); WebApplicationException exception = null; try{ DataValidator.validate(license); } catch (WebApplicationException e){ exception = e; } assertNull(exception); }
@Test public void licenseWithNameNullIsNotValid(){ final License license = DataModelFactory.createLicense(null, "longName", null, null, null); WebApplicationException exception = null; try{ DataValidator.validate(license); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void licenseWithNameEmptyIsNotValid(){ final License license = DataModelFactory.createLicense("", "longName", null, null, null); WebApplicationException exception = null; try{ DataValidator.validate(license); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void licenseWithLongNameNullIsNotValid(){ final License license = DataModelFactory.createLicense("name", null, null, null, null); WebApplicationException exception = null; try{ DataValidator.validate(license); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void licenseWithLongNameEmptyIsNotValid(){ final License license = DataModelFactory.createLicense("name", "", null, null, null); WebApplicationException exception = null; try{ DataValidator.validate(license); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void licenseWithRegexpThatCompileIsValid(){ final License license = DataModelFactory.createLicense("name", "longName", null, ".*", null); WebApplicationException exception = null; try{ DataValidator.validate(license); } catch (WebApplicationException e){ exception = e; } assertNull(exception); }
@Test public void licenseWithRegexpThatDoesNotCompileIsNotValid(){ final License license = DataModelFactory.createLicense("name", "longName", null, "*", null); WebApplicationException exception = null; try{ DataValidator.validate(license); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void validateModule(){ final Module module = DataModelFactory.createModule("name", "version"); module.addArtifact(DataModelFactory.createArtifact("groupId", "artifactId", "version", null, null, null)); module.addSubmodule(DataModelFactory.createModule("sub-module", "version")); WebApplicationException exception = null; try{ DataValidator.validate(module); } catch (WebApplicationException e){ exception = e; } assertNull(exception); }
@Test public void moduleWithNameEmptyIsNotValid(){ final Module module = DataModelFactory.createModule("", "version"); WebApplicationException exception = null; try{ DataValidator.validate(module); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void moduleWithNameNullIsNotValid(){ final Module module = DataModelFactory.createModule(null, "version"); WebApplicationException exception = null; try{ DataValidator.validate(module); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void moduleWithVersionEmptyIsNotValid(){ final Module module = DataModelFactory.createModule("name", ""); WebApplicationException exception = null; try{ DataValidator.validate(module); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void moduleWithVersionNullIsNotValid(){ final Module module = DataModelFactory.createModule("name", null); WebApplicationException exception = null; try{ DataValidator.validate(module); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void validateAnOrganization(){ final Organization organization = DataModelFactory.createOrganization("test"); WebApplicationException exception = null; try{ DataValidator.validate(organization); } catch (WebApplicationException e){ exception = e; } assertNull(exception); }
@Test public void organizationWithNameEmptyIsNotValid(){ final Organization organization = DataModelFactory.createOrganization(""); WebApplicationException exception = null; try{ DataValidator.validate(organization); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void organizationWithNameNullIsNotValid(){ final Organization organization = DataModelFactory.createOrganization(null); WebApplicationException exception = null; try{ DataValidator.validate(organization); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void validateArtifactQuery() throws IOException{ final ArtifactQuery artifactQuery = DataModelFactory.createArtifactQuery("toto", 0 , "file.jar", "6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c", "ServicePack", ""); WebApplicationException exception = null; try{ DataValidator.validate(artifactQuery); } catch (WebApplicationException e){ exception = e; } assertNull(exception); }
@Test public void artifactQueryWithMissingUser() throws IOException{ final ArtifactQuery artifactQuery = DataModelFactory.createArtifactQuery(null, 0 , "file.jar", "6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c", "ServicePack", ""); WebApplicationException exception = null; try{ DataValidator.validate(artifactQuery); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void artifactQueryWithInvalidStage() throws IOException{ final ArtifactQuery artifactQuery = DataModelFactory.createArtifactQuery("toto", -1 , "file.jar", "6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c", "ServicePack", ""); WebApplicationException exception = null; try{ DataValidator.validate(artifactQuery); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void artifactQueryWithMissingChecksum() throws IOException{ final ArtifactQuery artifactQuery = DataModelFactory.createArtifactQuery("toto", 0 , "file.jar", null, "ServicePack", ""); WebApplicationException exception = null; try{ DataValidator.validate(artifactQuery); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void artifactQueryWithMissingFilename() throws IOException{ final ArtifactQuery artifactQuery = DataModelFactory.createArtifactQuery("toto", 0 , null, "6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c", "ServicePack", ""); WebApplicationException exception = null; try{ DataValidator.validate(artifactQuery); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void artifactQueryWithInvalidChecksum() throws IOException{ final ArtifactQuery artifactQuery = DataModelFactory.createArtifactQuery("toto", 0 , "file.jar", "6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821Y", "ServicePack", ""); WebApplicationException exception = null; try{ DataValidator.validate(artifactQuery); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }
@Test public void artifactQueryWithMissingFiletype() throws IOException{ final ArtifactQuery artifactQuery = DataModelFactory.createArtifactQuery("toto", 0 , "file.jar", "6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c", null, ""); WebApplicationException exception = null; try{ DataValidator.validate(artifactQuery); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); }