aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-database
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2007-08-03 16:02:00 +0000
committerBrett Porter <brett@apache.org>2007-08-03 16:02:00 +0000
commit0dc2c29c92ed68ccf1e7a266166a02908d06c699 (patch)
treee3babf1c220be5a6f47b51ac7632adafbfe42adb /archiva-database
parent83dfd74838cc58cdb8a9de6d1883f1969b811552 (diff)
downloadarchiva-0dc2c29c92ed68ccf1e7a266166a02908d06c699.tar.gz
archiva-0dc2c29c92ed68ccf1e7a266166a02908d06c699.zip
[MRM-329] revised reporting actions
Submitted by: Teodoro Cue git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@562511 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-database')
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/DeclarativeConstraint.java39
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RangeConstraint.java9
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraint.java21
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByRepositoryIdConstraint.java21
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraint.java (renamed from archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByArtifactIdConstraint.java)27
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueFieldConstraint.java57
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RangeConstraintTest.java88
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraintTest.java93
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByRepositoryIdConstraintTest.java93
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraintTest.java122
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/UniqueFieldConstraintTest.java117
11 files changed, 651 insertions, 36 deletions
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/DeclarativeConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/DeclarativeConstraint.java
index c87df33ab..15fa14e2b 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/DeclarativeConstraint.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/DeclarativeConstraint.java
@@ -20,84 +20,85 @@ package org.apache.maven.archiva.database;
*/
/**
- * DeclarativeConstraint
+ * DeclarativeConstraint
*
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
* @version $Id$
*/
-public interface DeclarativeConstraint extends Constraint
+public interface DeclarativeConstraint
+ extends Constraint
{
/**
* Get the declared imports used for this query. (optional)
- *
+ * <p/>
* NOTE: This is DAO implementation specific.
- *
+ *
* @return the imports. (can be null)
*/
public abstract String[] getDeclaredImports();
/**
* Get the declared parameters used for this query. (optional)
- *
+ * <p/>
* NOTE: This is DAO implementation specific.
- *
+ *
* @return the parameters. (can be null)
*/
public abstract String[] getDeclaredParameters();
-
+
/**
* The JDOQL filter to apply to the query. (optional)
- *
+ * <p/>
* NOTE: This is DAO implementation specific.
- *
+ *
* @return the filter to apply. (can be null)
*/
public abstract String getFilter();
/**
* Get the parameters used for this query. (required if using {@link #getDeclaredParameters()} )
- *
+ * <p/>
* NOTE: This is DAO implementation specific.
- *
+ *
* @return the parameters. (can be null)
*/
public abstract Object[] getParameters();
/**
* Get the sort direction name.
- *
+ *
* @return the sort direction name. ("ASC" or "DESC") (only valid if {@link #getSortColumn()} is specified.)
*/
public abstract String getSortDirection();
/**
* Get the sort column name.
- *
+ *
* @return the sort column name. (can be null)
*/
public abstract String getSortColumn();
-
+
/**
* Get the variables used within the query.
- *
+ * <p/>
* NOTE: This is DAO implementation specific.
- *
+ *
* @return the variables used within the query.
*/
public abstract String[] getVariables();
/**
* Get the SELECT WHERE (condition) value for the constraint.
- *
+ *
* @return the equivalent of the SELECT WHERE (condition) value for this constraint. (can be null)
*/
public abstract String getWhereCondition();
/**
* Get the declared range used for this query. (optional)
- *
+ * <p/>
* NOTE: This is DAO implementation specific.
- *
+ *
* @return the range. (can be null)
*/
public abstract int[] getRange();
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RangeConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RangeConstraint.java
index 9fb821d28..3eead3323 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RangeConstraint.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RangeConstraint.java
@@ -22,15 +22,20 @@ package org.apache.maven.archiva.database.constraints;
import org.apache.maven.archiva.database.Constraint;
/**
- * RangeConstraint
+ * RangeConstraint
*/
public class RangeConstraint
extends AbstractDeclarativeConstraint
implements Constraint
{
+ public RangeConstraint()
+ {
+ this.range = null;
+ }
+
public RangeConstraint( int[] range )
{
- this.range = range;
+ this.range = range;
}
public String getSortColumn()
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraint.java
index fbeff0932..1a0971acb 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraint.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraint.java
@@ -24,16 +24,29 @@ import org.apache.maven.archiva.database.Constraint;
/**
* RepositoryProblemByGroupIdConstraint
*/
-public class RepositoryProblemByGroupIdConstraint extends RangeConstraint implements Constraint
+public class RepositoryProblemByGroupIdConstraint
+ extends RangeConstraint
+ implements Constraint
{
private String whereClause;
+ private void createWhereClause( String desiredGroupId )
+ {
+ whereClause = "groupId == desiredGroupId";
+ declParams = new String[]{"String desiredGroupId"};
+ params = new Object[]{desiredGroupId};
+ }
+
+ public RepositoryProblemByGroupIdConstraint( String desiredGroupId )
+ {
+ super();
+ createWhereClause( desiredGroupId );
+ }
+
public RepositoryProblemByGroupIdConstraint( int[] range, String desiredGroupId )
{
super( range );
- whereClause = "groupId == desiredGroupId";
- declParams = new String[] { "String desiredGroupId" };
- params = new Object[] { desiredGroupId };
+ createWhereClause( desiredGroupId );
}
public String getSortColumn()
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByRepositoryIdConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByRepositoryIdConstraint.java
index 08b024b27..d1b5de7d8 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByRepositoryIdConstraint.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByRepositoryIdConstraint.java
@@ -24,16 +24,29 @@ import org.apache.maven.archiva.database.Constraint;
/**
* RepositoryProblemByRepositoryIdConstraint
*/
-public class RepositoryProblemByRepositoryIdConstraint extends RangeConstraint implements Constraint
+public class RepositoryProblemByRepositoryIdConstraint
+ extends RangeConstraint
+ implements Constraint
{
private String whereClause;
+ private void createWhereClause( String desiredRepositoryId )
+ {
+ whereClause = "repositoryId == desiredRepositoryId";
+ declParams = new String[]{"String desiredRepositoryId"};
+ params = new Object[]{desiredRepositoryId};
+ }
+
+ public RepositoryProblemByRepositoryIdConstraint( String desiredRepositoryId )
+ {
+ super();
+ createWhereClause( desiredRepositoryId );
+ }
+
public RepositoryProblemByRepositoryIdConstraint( int[] range, String desiredRepositoryId )
{
super( range );
- whereClause = "repositoryId == desiredRepositoryId";
- declParams = new String[] { "String desiredRepositoryId" };
- params = new Object[] { desiredRepositoryId };
+ createWhereClause( desiredRepositoryId );
}
public String getSortColumn()
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByArtifactIdConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraint.java
index a94aed873..3c2c997ac 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByArtifactIdConstraint.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraint.java
@@ -22,23 +22,36 @@ package org.apache.maven.archiva.database.constraints;
import org.apache.maven.archiva.database.Constraint;
/**
- * RepositoryProblemByArtifactIdConstraint
+ * RepositoryProblemConstraint
*/
-public class RepositoryProblemByArtifactIdConstraint extends RangeConstraint implements Constraint
+public class RepositoryProblemConstraint
+ extends RangeConstraint
+ implements Constraint
{
private String whereClause;
- public RepositoryProblemByArtifactIdConstraint( int[] range, String desiredArtifactId )
+ private void createWhereClause( String desiredGroupId, String desiredRepositoryId )
+ {
+ whereClause = "groupId == desiredGroupId && repositoryId == desiredRepositoryId";
+ declParams = new String[]{"String desiredGroupId", "String desiredRepositoryId"};
+ params = new Object[]{desiredGroupId, desiredRepositoryId};
+ }
+
+ public RepositoryProblemConstraint( String desiredGroupId, String desiredRepositoryId )
+ {
+ super();
+ createWhereClause( desiredGroupId, desiredRepositoryId );
+ }
+
+ public RepositoryProblemConstraint( int[] range, String desiredGroupId, String desiredRepositoryId )
{
super( range );
- whereClause = "artifactId == desiredArtifactId";
- declParams = new String[] { "String desiredArtifactId" };
- params = new Object[] { desiredArtifactId };
+ createWhereClause( desiredGroupId, desiredRepositoryId );
}
public String getSortColumn()
{
- return "groupId";
+ return "artifactId";
}
public String getWhereCondition()
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueFieldConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueFieldConstraint.java
new file mode 100644
index 000000000..8e22ac255
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueFieldConstraint.java
@@ -0,0 +1,57 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.Constraint;
+
+/**
+ * UniqueFieldConstraint
+ */
+public class UniqueFieldConstraint
+ extends AbstractSimpleConstraint
+ implements Constraint
+{
+ private String sql;
+
+ public UniqueFieldConstraint( String className, String fieldName )
+ {
+ sql = "SELECT " + fieldName + " FROM " + className + " GROUP BY " + fieldName + " ORDER BY " + fieldName +
+ " ASCENDING";
+ }
+
+ public UniqueFieldConstraint( String className, String fieldName, String fieldNamePrefix )
+ {
+ sql = "SELECT " + fieldName + " FROM " + className + " WHERE " + fieldName +
+ ".startsWith( fieldPrefix ) PARAMETERS String fieldPrefix GROUP BY " + fieldName + " ORDER BY " +
+ fieldName + " ASCENDING";
+
+ super.params = new Object[]{fieldNamePrefix};
+ }
+
+ public Class getResultClass()
+ {
+ return String.class;
+ }
+
+ public String getSelectSql()
+ {
+ return sql;
+ }
+}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RangeConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RangeConstraintTest.java
new file mode 100644
index 000000000..aa0618955
--- /dev/null
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RangeConstraintTest.java
@@ -0,0 +1,88 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.database.RepositoryProblemDAO;
+import org.apache.maven.archiva.model.RepositoryProblem;
+
+import java.util.List;
+
+/**
+ * RangeConstraintTest
+ */
+public class RangeConstraintTest
+ extends AbstractArchivaDatabaseTestCase
+{
+ private RepositoryProblemDAO repoProblemDao;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
+ repoProblemDao = dao.getRepositoryProblemDAO();
+ }
+
+ public RepositoryProblem createRepoProblem()
+ {
+ RepositoryProblem repoProblem = new RepositoryProblem();
+
+ repoProblem.setGroupId( "groupId" );
+ repoProblem.setArtifactId( "artifactId" );
+ repoProblem.setMessage( "message" );
+ repoProblem.setOrigin( "origin" );
+ repoProblem.setPath( "path" );
+ repoProblem.setRepositoryId( "repositoryId" );
+ repoProblem.setType( "type" );
+ repoProblem.setVersion( "version" );
+
+ return repoProblem;
+ }
+
+ public void testConstraint()
+ throws Exception
+ {
+ repoProblemDao.saveRepositoryProblem( createRepoProblem() );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem() );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem() );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem() );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem() );
+
+ assertConstraint( 0, new RangeConstraint( new int[]{5, 10} ) );
+ assertConstraint( 1, new RangeConstraint( new int[]{0, 1} ) );
+ assertConstraint( 2, new RangeConstraint( new int[]{0, 2} ) );
+ assertConstraint( 3, new RangeConstraint( new int[]{0, 3} ) );
+ assertConstraint( 4, new RangeConstraint( new int[]{0, 4} ) );
+ assertConstraint( 5, new RangeConstraint( new int[]{0, 5} ) );
+ assertConstraint( 5, new RangeConstraint() );
+ }
+
+ private void assertConstraint( int expectedHits, Constraint constraint )
+ throws Exception
+ {
+ List results = repoProblemDao.queryRepositoryProblems( constraint );
+ assertNotNull( "Range Constraint: Not Null", results );
+ assertEquals( "Range Constraint: Results.size", expectedHits, results.size() );
+ }
+}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraintTest.java
new file mode 100644
index 000000000..49d4713e0
--- /dev/null
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraintTest.java
@@ -0,0 +1,93 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.database.RepositoryProblemDAO;
+import org.apache.maven.archiva.model.RepositoryProblem;
+
+import java.util.List;
+
+/**
+ * RepositoryProblemByGroupIdConstraintTest
+ */
+public class RepositoryProblemByGroupIdConstraintTest
+ extends AbstractArchivaDatabaseTestCase
+{
+ private static final String GROUP_ID_1 = "org.apache.maven.archiva.test.1";
+
+ private static final String GROUP_ID_2 = "org.apache.maven.archiva.test.2";
+
+ private static final String GROUP_ID_3 = "org.apache.maven.archiva.test.3";
+
+ private RepositoryProblemDAO repoProblemDao;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
+ repoProblemDao = dao.getRepositoryProblemDAO();
+ }
+
+ public RepositoryProblem createRepoProblem( String groupId )
+ {
+ RepositoryProblem repoProblem = new RepositoryProblem();
+
+ repoProblem.setGroupId( groupId );
+ repoProblem.setArtifactId( "artifactId" );
+ repoProblem.setMessage( "message" );
+ repoProblem.setOrigin( "origin" );
+ repoProblem.setPath( "path" );
+ repoProblem.setRepositoryId( "repositoryId" );
+ repoProblem.setType( "type" );
+ repoProblem.setVersion( "version" );
+
+ return repoProblem;
+ }
+
+ public void testConstraint()
+ throws Exception
+ {
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1 ) );
+
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2 ) );
+
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
+
+ assertConstraint( 1, new RepositoryProblemByGroupIdConstraint( GROUP_ID_1 ) );
+ assertConstraint( 2, new RepositoryProblemByGroupIdConstraint( GROUP_ID_2 ) );
+ assertConstraint( 3, new RepositoryProblemByGroupIdConstraint( GROUP_ID_3 ) );
+ }
+
+ private void assertConstraint( int expectedHits, Constraint constraint )
+ throws Exception
+ {
+ List results = repoProblemDao.queryRepositoryProblems( constraint );
+ assertNotNull( "Repository Problems by Group Id: Not Null", results );
+ assertEquals( "Repository Problems by Group Id: Results.size", expectedHits, results.size() );
+ }
+}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByRepositoryIdConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByRepositoryIdConstraintTest.java
new file mode 100644
index 000000000..425fc0e8d
--- /dev/null
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByRepositoryIdConstraintTest.java
@@ -0,0 +1,93 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.database.RepositoryProblemDAO;
+import org.apache.maven.archiva.model.RepositoryProblem;
+
+import java.util.List;
+
+/**
+ * RepositoryProblemByRepositoryIdConstraintTest
+ */
+public class RepositoryProblemByRepositoryIdConstraintTest
+ extends AbstractArchivaDatabaseTestCase
+{
+ private static final String REPO_ID_1 = "test-repo-1";
+
+ private static final String REPO_ID_2 = "test-repo-2";
+
+ private static final String REPO_ID_3 = "test-repo-3";
+
+ private RepositoryProblemDAO repoProblemDao;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
+ repoProblemDao = dao.getRepositoryProblemDAO();
+ }
+
+ public RepositoryProblem createRepoProblem( String repoId )
+ {
+ RepositoryProblem repoProblem = new RepositoryProblem();
+
+ repoProblem.setGroupId( "groupId" );
+ repoProblem.setArtifactId( "artifactId" );
+ repoProblem.setMessage( "message" );
+ repoProblem.setOrigin( "origin" );
+ repoProblem.setPath( "path" );
+ repoProblem.setRepositoryId( repoId );
+ repoProblem.setType( "type" );
+ repoProblem.setVersion( "version" );
+
+ return repoProblem;
+ }
+
+ public void testConstraint()
+ throws Exception
+ {
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( REPO_ID_1 ) );
+
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( REPO_ID_2 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( REPO_ID_2 ) );
+
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( REPO_ID_3 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( REPO_ID_3 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( REPO_ID_3 ) );
+
+ assertConstraint( 1, new RepositoryProblemByRepositoryIdConstraint( REPO_ID_1 ) );
+ assertConstraint( 2, new RepositoryProblemByRepositoryIdConstraint( REPO_ID_2 ) );
+ assertConstraint( 3, new RepositoryProblemByRepositoryIdConstraint( REPO_ID_3 ) );
+ }
+
+ private void assertConstraint( int expectedHits, Constraint constraint )
+ throws Exception
+ {
+ List results = repoProblemDao.queryRepositoryProblems( constraint );
+ assertNotNull( "Repository Problems by Repository Id: Not Null", results );
+ assertEquals( "Repository Problems by Repository Id: Results.size", expectedHits, results.size() );
+ }
+}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraintTest.java
new file mode 100644
index 000000000..e0d77b31a
--- /dev/null
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraintTest.java
@@ -0,0 +1,122 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.database.RepositoryProblemDAO;
+import org.apache.maven.archiva.model.RepositoryProblem;
+
+import java.util.List;
+
+/**
+ * RepositoryProblemConstraintTest
+ */
+public class RepositoryProblemConstraintTest
+ extends AbstractArchivaDatabaseTestCase
+{
+ private static final String GROUP_ID_1 = "org.apache.maven.archiva.test.1";
+
+ private static final String GROUP_ID_2 = "org.apache.maven.archiva.test.2";
+
+ private static final String GROUP_ID_3 = "org.apache.maven.archiva.test.3";
+
+ private static final String GROUP_ID_4 = "org.apache.maven.archiva.test.4";
+
+ private static final String REPO_ID_1 = "test-repo-1";
+
+ private static final String REPO_ID_2 = "test-repo-2";
+
+ private static final String REPO_ID_3 = "test-repo-3";
+
+ private static final String REPO_ID_4 = "test-repo-4";
+
+ private RepositoryProblemDAO repoProblemDao;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
+ repoProblemDao = dao.getRepositoryProblemDAO();
+ }
+
+ public RepositoryProblem createRepoProblem( String groupId, String repoId )
+ {
+ RepositoryProblem repoProblem = new RepositoryProblem();
+
+ repoProblem.setGroupId( groupId );
+ repoProblem.setArtifactId( "artifactId" );
+ repoProblem.setMessage( "message" );
+ repoProblem.setOrigin( "origin" );
+ repoProblem.setPath( "path" );
+ repoProblem.setRepositoryId( repoId );
+ repoProblem.setType( "type" );
+ repoProblem.setVersion( "version" );
+
+ return repoProblem;
+ }
+
+ public void testGroupIdConstraint()
+ throws Exception
+ {
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_1 ) );
+
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2, REPO_ID_1 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2, REPO_ID_1 ) );
+
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3, REPO_ID_1 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3, REPO_ID_1 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3, REPO_ID_1 ) );
+
+ assertConstraint( 1, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_1 ) );
+ assertConstraint( 2, new RepositoryProblemConstraint( GROUP_ID_2, REPO_ID_1 ) );
+ assertConstraint( 3, new RepositoryProblemConstraint( GROUP_ID_3, REPO_ID_1 ) );
+ assertConstraint( 0, new RepositoryProblemConstraint( GROUP_ID_4, REPO_ID_1 ) );
+ }
+
+ public void testRepoIdConstraint()
+ throws Exception
+ {
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_1 ) );
+
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_2 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_2 ) );
+
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_3 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_3 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1, REPO_ID_3 ) );
+
+ assertConstraint( 1, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_1 ) );
+ assertConstraint( 2, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_2 ) );
+ assertConstraint( 3, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_3 ) );
+ assertConstraint( 0, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_4 ) );
+ }
+
+ private void assertConstraint( int expectedHits, Constraint constraint )
+ throws Exception
+ {
+ List results = repoProblemDao.queryRepositoryProblems( constraint );
+ assertNotNull( "Repository Problems: Not Null", results );
+ assertEquals( "Repository Problems: Results.size", expectedHits, results.size() );
+ }
+}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/UniqueFieldConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/UniqueFieldConstraintTest.java
new file mode 100644
index 000000000..b453281fa
--- /dev/null
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/UniqueFieldConstraintTest.java
@@ -0,0 +1,117 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.ArtifactDAO;
+import org.apache.maven.archiva.database.RepositoryProblemDAO;
+import org.apache.maven.archiva.database.SimpleConstraint;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.model.ArchivaArtifactModel;
+import org.apache.maven.archiva.model.RepositoryProblem;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * UniqueFieldConstraintTest
+ */
+public class UniqueFieldConstraintTest
+ extends AbstractArchivaDatabaseTestCase
+{
+ private static final String GROUP_ID_1 = "org.apache.maven.archiva.test.1";
+
+ private static final String GROUP_ID_2 = "org.apache.maven.archiva.test.2";
+
+ private static final String GROUP_ID_3 = "org.apache.maven.archiva.test.3";
+
+ private ArchivaDAO archivaDao;
+
+ private ArtifactDAO artifactDao;
+
+ private RepositoryProblemDAO repoProblemDao;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ archivaDao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
+ artifactDao = archivaDao.getArtifactDAO();
+ repoProblemDao = archivaDao.getRepositoryProblemDAO();
+ }
+
+ public ArchivaArtifact createArtifact( String groupId )
+ {
+ ArchivaArtifact artifact = artifactDao.createArtifact( groupId, "artifactId", "version", "classifier", "jar" );
+
+ artifact.getModel().setLastModified( new Date() );
+ artifact.getModel().setRepositoryId( "repoId" );
+
+ return artifact;
+ }
+
+ public RepositoryProblem createRepoProblem( String groupId )
+ {
+ RepositoryProblem repoProblem = new RepositoryProblem();
+
+ repoProblem.setGroupId( groupId );
+ repoProblem.setArtifactId( "artifactId" );
+ repoProblem.setMessage( "message" );
+ repoProblem.setOrigin( "origin" );
+ repoProblem.setPath( "path" );
+ repoProblem.setRepositoryId( "repoId" );
+ repoProblem.setType( "type" );
+ repoProblem.setVersion( "version" );
+
+ return repoProblem;
+ }
+
+ public void testArtifact()
+ throws Exception
+ {
+ artifactDao.saveArtifact( createArtifact( GROUP_ID_1 ) );
+ artifactDao.saveArtifact( createArtifact( GROUP_ID_2 ) );
+ artifactDao.saveArtifact( createArtifact( GROUP_ID_3 ) );
+
+ assertConstraint( 1, new UniqueFieldConstraint( ArchivaArtifactModel.class.getName(), "artifactId" ) );
+ assertConstraint( 3, new UniqueFieldConstraint( ArchivaArtifactModel.class.getName(), "groupId" ) );
+ }
+
+ public void testRepoProblem()
+ throws Exception
+ {
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_1 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_2 ) );
+ repoProblemDao.saveRepositoryProblem( createRepoProblem( GROUP_ID_3 ) );
+
+ assertConstraint( 1, new UniqueFieldConstraint( RepositoryProblem.class.getName(), "artifactId" ) );
+ assertConstraint( 3, new UniqueFieldConstraint( RepositoryProblem.class.getName(), "groupId" ) );
+ }
+
+ private void assertConstraint( int expectedHits, SimpleConstraint constraint )
+ throws Exception
+ {
+ List results = archivaDao.query( constraint );
+ assertNotNull( "Repository Problems: Not Null", results );
+ assertEquals( "Repository Problems: Results.size", expectedHits, results.size() );
+ }
+}