diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/solr/admin/SolrE2eAdminTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/solr/admin/SolrE2eAdminTest.java index 0ae0abd97..91060b11a 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/solr/admin/SolrE2eAdminTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/solr/admin/SolrE2eAdminTest.java @@ -15,6 +15,7 @@ package org.alfresco.test.search.functional.searchServices.solr.admin; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.alfresco.rest.core.RestResponse; @@ -27,7 +28,7 @@ import org.testng.annotations.Test; /** * End to end tests for SOLR Admin actions REST API, available from: * - * http://:/solr/admin/cores?action=* + * http://:/solr/admin/cores?action=(actionName) * * @author aborroy * @@ -36,88 +37,198 @@ import org.testng.annotations.Test; public class SolrE2eAdminTest extends AbstractE2EFunctionalTest { - // SOLR default response status codes (returned in responseHeader.status) - private static final String SOLR_RESPONSE_STATUS_OK = "0"; - private static final String SOLR_RESPONSE_STATUS_INTERNAL_ERROR = "400"; + private static final Integer SOLR_RESPONSE_STATUS_OK = 0; // Alfresco SOLR action response status identifiers private static final String ACTION_RESPONSE_REPORT = "report"; // Default Alfresco SOLR Core Names - List defaultCoreNames = new ArrayList<>(List.of("alfresco", "archive")); + private static final List DEFAULT_CORE_NAMES = new ArrayList<>(List.of("alfresco", "archive")); + + /** + * Check that SOLR Response Header contains a Query Time (qtime) and status equals to 0 + * @param response SOLR REST API Response in JSON + */ + private void checkResponseStatusOk(RestResponse response) + { + Integer qtime = response.getResponse().body().jsonPath().get("responseHeader.QTime"); + Assert.assertTrue(qtime >= 0, "Expeted responseHeader.QTime to be a positive number"); + Integer status = response.getResponse().body().jsonPath().get("responseHeader.status"); + Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK, "Expected " + SOLR_RESPONSE_STATUS_OK + " in responseHeader.status,"); + } + /** + * Node Report for every core. + * @throws Exception + */ @Test(priority = 1) public void testNodeReport() throws Exception { - String nodeid = "200"; + Integer nodeid = 200; RestResponse response = restClient.withParams("nodeid=" + nodeid).withSolrAdminAPI().getAction("nodeReport"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String report = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT).toString(); - Assert.assertNotNull(report); + DEFAULT_CORE_NAMES.forEach(core -> { + Integer reportNodeid = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + "." + core + ".'Node DBID'"); + Assert.assertEquals(reportNodeid, nodeid, "Expected " + nodeid + " in " + ACTION_RESPONSE_REPORT + "." + core + ".'Node DBID',"); + }); + } + + /** + * Node Report for an specific core. + * @throws Exception + */ + @Test(priority = 2) + public void testNodeReportCore() throws Exception + { + final Integer nodeid = 200; - defaultCoreNames.forEach(core -> { - Assert.assertNotNull(response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + "." + core)); + DEFAULT_CORE_NAMES.forEach(core -> { + + try + { + + RestResponse response = restClient.withParams("nodeid=" + nodeid, "core=" + core).withSolrAdminAPI().getAction("nodeReport"); + + checkResponseStatusOk(response); + + Integer reportNodeid = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + "." + core + ".'Node DBID'"); + Assert.assertEquals(reportNodeid, nodeid, "Expected " + nodeid + " in " + ACTION_RESPONSE_REPORT + "." + core + ".'Node DBID',"); + + } + catch (Exception e) + { + throw new RuntimeException(e); + } + }); } /** * Node Report requires "nodeid" parameter. - * This test will fail as we are missing to pass the parameter. + * This test will return an error as we are missing to pass the parameter. * @throws Exception */ - @Test(priority = 2) + @Test(priority = 3) public void testNodeReportError() throws Exception { RestResponse response = restClient.withSolrAdminAPI().getAction("nodeReport"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_INTERNAL_ERROR); - } - - @Test(priority = 3) - public void testAclReport() throws Exception - { - String aclid = "1"; - RestResponse response = restClient.withParams("aclid=" + aclid).withSolrAdminAPI().getAction("aclReport"); + checkResponseStatusOk(response); + + String reportError = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + ".error"); + Assert.assertEquals(reportError, "No nodeid parameter set.", "Unexpected message in " + ACTION_RESPONSE_REPORT + ".error,"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); - - String report = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT).toString(); - Assert.assertNotNull(report); } /** - * Acl Report requires "aclid" parameter. - * This test will fail as we are missing to pass the parameter. + * ACL Report for every core. * @throws Exception */ @Test(priority = 4) + public void testAclReport() throws Exception + { + Integer aclid = 1; + RestResponse response = restClient.withParams("aclid=" + aclid).withSolrAdminAPI().getAction("aclReport"); + + checkResponseStatusOk(response); + + DEFAULT_CORE_NAMES.forEach(core -> { + Integer reportAclid = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + "." + core + ".'Acl Id'"); + Assert.assertEquals(reportAclid, aclid, "Expected " + aclid + " in " + ACTION_RESPONSE_REPORT + "." + core + ".'Acl Id',"); + }); + } + + /** + * ACL Report for an specific core. + * @throws Exception + */ + @Test(priority = 5) + public void testAclReportCore() throws Exception + { + final Integer aclid = 1; + DEFAULT_CORE_NAMES.forEach(core -> { + + try + { + RestResponse response = restClient.withParams("aclid=" + aclid, "core=" + core).withSolrAdminAPI().getAction("aclReport"); + + checkResponseStatusOk(response); + + Integer reportAclid = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + "." + core + ".'Acl Id'"); + Assert.assertEquals(reportAclid, aclid, "Expected " + aclid + " in " + ACTION_RESPONSE_REPORT + "." + core + ".'Acl Id',"); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + }); + } + + /** + * ACL Report requires "aclid" parameter. + * This test will fail as we are missing to pass the parameter. + * @throws Exception + */ + @Test(priority = 6) public void testAclReportError() throws Exception { RestResponse response = restClient.withSolrAdminAPI().getAction("aclReport"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_INTERNAL_ERROR); + checkResponseStatusOk(response); + + String reportError = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + ".error"); + Assert.assertEquals(reportError, "No aclid parameter set.", "Unexpected message in " + ACTION_RESPONSE_REPORT + ".error,"); } - @Test(priority = 5) + /** + * TX Report for every core. + * @throws Exception + */ + @Test(priority = 7) public void testTxReport() throws Exception { - String coreName = "alfresco"; - String txid = "1"; + Integer txid = 1; - RestResponse response = restClient.withParams("coreName=" + coreName, "txid=" + txid).withSolrAdminAPI().getAction("txReport"); + RestResponse response = restClient.withParams("txid=" + txid).withSolrAdminAPI().getAction("txReport"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String report = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT).toString(); - Assert.assertNotNull(report); + DEFAULT_CORE_NAMES.forEach(core -> { + Integer reportTxid = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + "." + core + ".TXID"); + Assert.assertEquals(reportTxid, txid, "Expected " + txid + " in " + ACTION_RESPONSE_REPORT + "." + core + ".TXID,"); + }); + } + + /** + * TX Report for an specific core. + * @throws Exception + */ + @Test(priority = 8) + public void testTxReportCore() throws Exception + { + final Integer txid = 1; + DEFAULT_CORE_NAMES.forEach(core -> { + + try + { + + RestResponse response = restClient.withParams("coreName=" + core, "txid=" + txid).withSolrAdminAPI().getAction("txReport"); + + checkResponseStatusOk(response); + + Integer reportTxid = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + "." + core + ".TXID"); + Assert.assertEquals(reportTxid, txid, "Expected " + txid + " in " + ACTION_RESPONSE_REPORT + "." + core + ".TXID,"); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + }); } /** @@ -125,27 +236,63 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest * This test will fail as we are missing to pass the parameter. * @throws Exception */ - @Test(priority = 6) + @Test(priority = 9) public void testTxReportError() throws Exception { - RestResponse response = restClient.withSolrAdminAPI().getAction("txReport"); + String coreName = "alfresco"; - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_INTERNAL_ERROR); + RestResponse response = restClient.withParams("coreName=" + coreName).withSolrAdminAPI().getAction("txReport"); + + checkResponseStatusOk(response); + + String reportError = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + ".error"); + Assert.assertEquals(reportError, "No txid parameter set.", "Unexpected message in " + ACTION_RESPONSE_REPORT + ".error,"); } - @Test(priority = 7) + /** + * ACL TX Report for every core. + * @throws Exception + */ + @Test(priority = 10) public void testAclTxReport() throws Exception { - String acltxid = "1"; + Integer acltxid = 1; RestResponse response = restClient.withParams("acltxid=" + acltxid).withSolrAdminAPI().getAction("aclTxReport"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String report = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT).toString(); - Assert.assertNotNull(report); + DEFAULT_CORE_NAMES.forEach(core -> { + Integer reportAcltxidCount = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + "." + core + ".aclTxDbAclCount"); + Assert.assertEquals(reportAcltxidCount, Integer.valueOf(2), "Expected 2 in " + ACTION_RESPONSE_REPORT + "." + core + ".aclTxDbAclCount,"); + }); + } + + /** + * ACL TX Report for specific core. + * @throws Exception + */ + @Test(priority = 11) + public void testAclTxReportCore() throws Exception + { + final Integer acltxid = 1; + DEFAULT_CORE_NAMES.forEach(core -> { + + try + { + RestResponse response = restClient.withParams("acltxid=" + acltxid, "core=" + core).withSolrAdminAPI().getAction("aclTxReport"); + + checkResponseStatusOk(response); + + Integer reportAcltxidCount = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + "." + core + ".aclTxDbAclCount"); + Assert.assertEquals(reportAcltxidCount, Integer.valueOf(2), "Expected 2 in " + ACTION_RESPONSE_REPORT + "." + core + ".aclTxDbAclCount,"); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + }); } /** @@ -153,90 +300,199 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest * This test will fail as we are missing to pass the parameter. * @throws Exception */ - @Test(priority = 8) + @Test(priority = 12) public void testAclTxReportError() throws Exception { RestResponse response = restClient.withSolrAdminAPI().getAction("aclTxReport"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_INTERNAL_ERROR); + checkResponseStatusOk(response); + + String reportError = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + ".error"); + Assert.assertEquals(reportError, "No acltxid parameter set.", "Unexpected message in " + ACTION_RESPONSE_REPORT + ".error,"); } - @Test(priority = 9) + /** + * Report for every core. + * @throws Exception + */ + @Test(priority = 13) public void testReport() throws Exception { RestResponse response = restClient.withSolrAdminAPI().getAction(ACTION_RESPONSE_REPORT); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String report = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT).toString(); - Assert.assertNotNull(report); + DEFAULT_CORE_NAMES.forEach(core -> { + Integer reportTxCount = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + "." + core + ".'DB transaction count'"); + Assert.assertTrue(reportTxCount > 0, "Expecting a positive integer in " + ACTION_RESPONSE_REPORT + "." + core + ".'DB transaction count',"); + }); } - @Test(priority = 10) + /** + * Report for specific core. + * @throws Exception + */ + @Test(priority = 14) + public void testReportCore() throws Exception + { + DEFAULT_CORE_NAMES.forEach(core -> { + + try + { + RestResponse response = restClient.withParams("coreName=" + core).withSolrAdminAPI().getAction(ACTION_RESPONSE_REPORT); + + checkResponseStatusOk(response); + + Integer reportTxCount = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + "." + core + ".'DB transaction count'"); + Assert.assertTrue(reportTxCount > 0, "Expecting a positive integer in " + ACTION_RESPONSE_REPORT + "." + core + ".'DB transaction count',"); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + }); + } + + /** + * Report using params. + * @throws Exception + */ + @Test(priority = 15) + public void testReportWithParams() throws Exception + { + Long fromTime = 0l; + Long toTime = 0l; + + RestResponse response = restClient.withParams("fromTime=" + fromTime, "toTime=" + toTime).withSolrAdminAPI() + .getAction(ACTION_RESPONSE_REPORT); + + checkResponseStatusOk(response); + + DEFAULT_CORE_NAMES.forEach(core -> { + Integer reportTxCount = response.getResponse().body().jsonPath().get(ACTION_RESPONSE_REPORT + "." + core + ".'DB transaction count'"); + Assert.assertTrue(reportTxCount == 0, "Expecting 0 in " + ACTION_RESPONSE_REPORT + "." + core + ".'DB transaction count',"); + }); + } + + /** + * Summary for every core. + * @throws Exception + */ + @Test(priority = 16) public void testSummary() throws Exception { - String core = "alfresco"; - - RestResponse response = restClient.withParams("core=" + core).withSolrAdminAPI().getAction("summary"); + RestResponse response = restClient.withSolrAdminAPI().getAction("summary"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String report = response.getResponse().body().jsonPath().get("Summary").toString(); - Assert.assertNotNull(report); + DEFAULT_CORE_NAMES.forEach(core -> { + Integer reportTxCount = response.getResponse().body().jsonPath().get("Summary." + core + ".'Alfresco Transactions in Index'"); + Assert.assertTrue(reportTxCount > 0, "Expecting a positive integer in Summary." + core + ".'Alfresco Transactions in Index',"); + + }); } - @Test(priority = 11) + /** + * Summary for specific core. + * @throws Exception + */ + @Test(priority = 17) + public void testSummaryCore() throws Exception + { + DEFAULT_CORE_NAMES.forEach(core -> { + + try + { + RestResponse response = restClient.withParams("core=" + core).withSolrAdminAPI().getAction("summary"); + + checkResponseStatusOk(response); + + Integer reportTxCount = response.getResponse().body().jsonPath().get("Summary." + core + ".'Alfresco Transactions in Index'"); + Assert.assertTrue(reportTxCount > 0, "Expecting a positive integer in Summary." + core + ".'Alfresco Transactions in Index',"); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + }); + } + + /** + * Check every core. + * @throws Exception + */ + @Test(priority = 18) public void testCheck() throws Exception { - String core = "alfresco"; + RestResponse response = restClient.withSolrAdminAPI().getAction("check"); - RestResponse response = restClient.withParams("core=" + core).withSolrAdminAPI().getAction("check"); + checkResponseStatusOk(response); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); - - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "success"); } + /** + * Check specific core. + * @throws Exception + */ + @Test(priority = 19) + public void testCheckCore() throws Exception + { + DEFAULT_CORE_NAMES.forEach(core -> { + + try + { + RestResponse response = restClient.withParams("core=" + core).withSolrAdminAPI().getAction("check"); + + checkResponseStatusOk(response); + + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); + Assert.assertEquals(actionStatus, "success"); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + }); + } + /** * This action only applies to DB_ID_RANGE Sharding method. * This test verifies expected result when using another deployment * @throws Exception */ - @Test(priority = 12) + @Test(priority = 20) public void testRangeCheck() throws Exception { String coreName = "alfresco"; RestResponse response = restClient.withParams("coreName=" + coreName).withSolrAdminAPI().getAction("rangeCheck"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String expand = response.getResponse().body().jsonPath().get("expand").toString(); - Assert.assertEquals(expand, "-1"); + Integer expand = response.getResponse().body().jsonPath().get("expand"); + Assert.assertEquals(expand, Integer.valueOf(-1), "Expansion is not allowed when not using Shard DB_ID_RANGE method,"); } /** * When using DB_ID_RANGE Sharding method, expand param is including a number of nodes to be extended. * @throws Exception */ - @Test(priority = 13, groups = { TestGroup.ASS_SHARDING_DB_ID_RANGE }) + @Test(priority = 21, groups = { TestGroup.ASS_SHARDING_DB_ID_RANGE }) public void testRangeCheckSharding() throws Exception { String coreName = "alfresco"; RestResponse response = restClient.withParams("coreName=" + coreName).withSolrAdminAPI().getAction("rangeCheck"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String expand = response.getResponse().body().jsonPath().get("expand").toString(); - Assert.assertNotEquals(expand, "-1"); + Integer expand = response.getResponse().body().jsonPath().get("expand"); + Assert.assertNotEquals(expand, Integer.valueOf(-1), "Expansion is a positive number when using Shard DB_ID_RANGE method,"); } /** @@ -244,7 +500,7 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest * This test verifies expected result when using another deployment * @throws Exception */ - @Test(priority = 14) + @Test(priority = 22) public void testExpand() throws Exception { String coreName = "alfresco"; @@ -252,19 +508,18 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest RestResponse response = restClient.withParams("coreName=" + coreName, "add=" + add).withSolrAdminAPI().getAction("expand"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); // This action only applies to DB_ID_RANGE Sharding method - String expand = response.getResponse().body().jsonPath().get("expand").toString(); - Assert.assertEquals(expand, "-1"); + Integer expand = response.getResponse().body().jsonPath().get("expand"); + Assert.assertEquals(expand, Integer.valueOf(-1), "Expansion is not allowed when not using Shard DB_ID_RANGE method,"); } /** * When using DB_ID_RANGE Sharding method, expand param is including a number of nodes extended. * @throws Exception */ - @Test(priority = 15, groups = { TestGroup.ASS_SHARDING_DB_ID_RANGE }) + @Test(priority = 23, groups = { TestGroup.ASS_SHARDING_DB_ID_RANGE }) public void testExpandSharding() throws Exception { String coreName = "alfresco"; @@ -272,107 +527,300 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest RestResponse response = restClient.withParams("coreName=" + coreName, "add=" + add).withSolrAdminAPI().getAction("expand"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); // This action only applies to DB_ID_RANGE Sharding method - String expand = response.getResponse().body().jsonPath().get("expand").toString(); - Assert.assertNotEquals(expand, "-1"); + Integer expand = response.getResponse().body().jsonPath().get("expand"); + Assert.assertNotEquals(expand, Integer.valueOf(-1), "Expansion is a positive number when using Shard DB_ID_RANGE method,"); } - @Test(priority = 16) + /** + * Purge TX in every core. + * @throws Exception + */ + @Test(priority = 24) public void testPurge() throws Exception { - String core = "alfresco"; - String txid = "1"; + Integer txid = 1; - RestResponse response = restClient.withParams("core=" + core, "txid=" + txid).withSolrAdminAPI().getAction("purge"); + RestResponse response = restClient.withParams("txid=" + txid).withSolrAdminAPI().getAction("purge"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "scheduled"); } - @Test(priority = 17) + /** + * Purge TX in specific core. + * @throws Exception + */ + @Test(priority = 25) + public void testPurgeCore() throws Exception + { + final Integer txid = 1; + + DEFAULT_CORE_NAMES.forEach(core -> { + + try + { + RestResponse response = restClient.withParams("core=" + core, "txid=" + txid).withSolrAdminAPI().getAction("purge"); + + checkResponseStatusOk(response); + + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); + Assert.assertEquals(actionStatus, "scheduled"); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + }); + } + + /** + * Purge with no params produces an empty response. + * @throws Exception + */ + @Test(priority = 26) + public void testPurgeEmpty() throws Exception + { + RestResponse response = restClient.withSolrAdminAPI().getAction("purge"); + + checkResponseStatusOk(response); + + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); + Assert.assertEquals(actionStatus, "scheduled"); + } + + /** + * FIX for every core. + * @throws Exception + */ + @Test(priority = 27, dependsOnMethods = "testPurge") public void testFix() throws Exception { - String core = "alfresco"; + RestResponse response = restClient.withSolrAdminAPI().getAction("fix"); - RestResponse response = restClient.withParams("core=" + core).withSolrAdminAPI().getAction("fix"); + checkResponseStatusOk(response); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + DEFAULT_CORE_NAMES.forEach(core -> { + List txToReindex = response.getResponse().body().jsonPath().get("action." + core +".txToReindex"); + Assert.assertTrue(txToReindex.size() >= 0, "Expected a list of transactions (or empty list) to be reindexed,"); + List aclToReindex = response.getResponse().body().jsonPath().get("action." + core + ".aclChangeSetToReindex"); + Assert.assertTrue(aclToReindex.size() >= 0, "Expected a list of ACLs (or empty list) to be reindexed,"); + }); - Assert.assertNotNull(response.getResponse().body().jsonPath().get("action." + core +".txToReindex")); - Assert.assertNotNull(response.getResponse().body().jsonPath().get("action." + core + ".aclChangeSetToReindex")); - - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "scheduled"); } - @Test(priority = 18) + /** + * FIX for specific core. + * @throws Exception + */ + @Test(priority = 28) + public void testFixCore() throws Exception + { + DEFAULT_CORE_NAMES.forEach(core -> { + + try + { + RestResponse response = restClient.withParams("core=" + core).withSolrAdminAPI().getAction("fix"); + + checkResponseStatusOk(response); + + List txToReindex = response.getResponse().body().jsonPath().get("action." + core +".txToReindex"); + Assert.assertTrue(txToReindex.size() >= 0, "Expected a list of transactions (or empty list) to be reindexed,"); + List aclToReindex = response.getResponse().body().jsonPath().get("action." + core + ".aclChangeSetToReindex"); + Assert.assertTrue(aclToReindex.size() >= 0, "Expected a list of ACLs (or empty list) to be reindexed,"); + + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); + Assert.assertEquals(actionStatus, "scheduled"); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + }); + } + + /** + * REINDEX for every core. + * @throws Exception + */ + @Test(priority = 29) public void testReindex() throws Exception { - String core = "alfresco"; - String txid = "1"; + Integer txid = 1; - RestResponse response = restClient.withParams("core=" + core, "txid=" + txid).withSolrAdminAPI().getAction("reindex"); + RestResponse response = restClient.withParams("txid=" + txid).withSolrAdminAPI().getAction("reindex"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); - Assert.assertEquals(actionStatus, "scheduled"); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); + Assert.assertEquals(actionStatus, "scheduled"); } - @Test(priority = 19) + /** + * REINDEX for specific core. + * @throws Exception + */ + @Test(priority = 30) + public void testReindexCore() throws Exception + { + Integer txid = 1; + + DEFAULT_CORE_NAMES.forEach(core -> { + + try + { + RestResponse response = restClient.withParams("core=" + core, "txid=" + txid).withSolrAdminAPI().getAction("reindex"); + + checkResponseStatusOk(response); + + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); + Assert.assertEquals(actionStatus, "scheduled"); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + }); + } + + /** + * RETRY for every core. + * @throws Exception + */ + @Test(priority = 31) public void testRetry() throws Exception { - String core = "alfresco"; + RestResponse response = restClient.withSolrAdminAPI().getAction("retry"); - RestResponse response = restClient.withParams("core=" + core).withSolrAdminAPI().getAction("retry"); + checkResponseStatusOk(response); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); - - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "scheduled"); + + DEFAULT_CORE_NAMES.forEach(core -> { + List errorNodeList = response.getResponse().body().jsonPath().get("action." + core); + Assert.assertEquals(errorNodeList, Arrays.asList(), "Expected no error nodes,"); + }); } - @Test(priority = 20) + /** + * RETRY for specific core. + * @throws Exception + */ + @Test(priority = 32) + public void testRetryCore() throws Exception + { + DEFAULT_CORE_NAMES.forEach(core -> { + + try + { + RestResponse response = restClient.withParams("core=" + core).withSolrAdminAPI().getAction("retry"); + + checkResponseStatusOk(response); + + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); + Assert.assertEquals(actionStatus, "scheduled"); + + List errorNodeList = response.getResponse().body().jsonPath().get("action." + core); + Assert.assertEquals(errorNodeList, Arrays.asList(), "Expected no error nodes,"); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + }); + } + + /** + * INDEX for every core. + * @throws Exception + */ + @Test(priority = 33) public void testIndex() throws Exception { - String core = "alfresco"; - String txid = "1"; + Integer txid = 1; - RestResponse response = restClient.withParams("core=" + core, "txid=" + txid).withSolrAdminAPI().getAction("index"); + RestResponse response = restClient.withParams("txid=" + txid).withSolrAdminAPI().getAction("index"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "scheduled"); } - @Test(priority = 21) + /** + * INDEX for specific core. + * @throws Exception + */ + @Test(priority = 34) + public void testIndexCore() throws Exception + { + final Integer txid = 1; + + DEFAULT_CORE_NAMES.forEach(core -> { + + try + { + RestResponse response = restClient.withParams("core=" + core, "txid=" + txid).withSolrAdminAPI().getAction("index"); + + checkResponseStatusOk(response); + + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); + Assert.assertEquals(actionStatus, "scheduled"); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + }); + } + + /** + * Reloads default log4j properties into memory. + * @throws Exception + */ + @Test(priority = 35) public void testLog4J() throws Exception { RestResponse response = restClient.withSolrAdminAPI().getAction("log4j"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "success"); } + /** + * This REST API call will fail as the specified resource to reload doesn't exist. + * @throws Exception + */ + @Test(priority = 36) + public void testLog4JError() throws Exception + { + RestResponse response = restClient.withParams("resource=log4j-unexisting.properties").withSolrAdminAPI().getAction("log4j"); + + checkResponseStatusOk(response); + + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); + Assert.assertEquals(actionStatus, "error"); + } + /** * This test will fail if it's executed twice * @throws Exception */ - @Test(priority = 22) + @Test(priority = 37) public void testNewCore() throws Exception { String core = "newCore"; @@ -382,18 +830,20 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest RestResponse response = restClient.withParams("coreName=" + core, "storeRef=" + storeRef, "template=" + template) .withSolrAdminAPI().getAction("newCore"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "success"); + + String actionCore = response.getResponse().body().jsonPath().get("action.core"); + Assert.assertEquals(actionCore, core, "Created core name is expected in action.core,"); } /** * When creating a core that already exists, this action fails. * @throws Exception */ - @Test(priority = 23) + @Test(priority = 38) public void testNewCoreError() throws Exception { String core = "alfresco"; @@ -402,24 +852,26 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest RestResponse response = restClient.withParams("coreName=" + core, "template=" + template) .withSolrAdminAPI().getAction("newCore"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "error"); } - @Test(priority = 24) + /** + * Reloads core configuration in memory. + * @throws Exception + */ + @Test(priority = 39) public void testUpdateCore() throws Exception { String core = "alfresco"; RestResponse response = restClient.withParams("coreName=" + core).withSolrAdminAPI().getAction("updateCore"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "success"); } @@ -427,17 +879,16 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest * When updating a core that doesn't exist, this action fails. * @throws Exception */ - @Test(priority = 25) + @Test(priority = 40) public void testUpdateCoreError() throws Exception { String core = "nonExistingCore"; RestResponse response = restClient.withParams("coreName=" + core).withSolrAdminAPI().getAction("updateCore"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "error"); } @@ -445,15 +896,14 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest * This test updates "shared.properties" memory loading for every SOLR core. * @throws Exception */ - @Test(priority = 26) + @Test(priority = 41) public void testUpdateShared() throws Exception { RestResponse response = restClient.withSolrAdminAPI().getAction("updateShared"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "success"); } @@ -461,7 +911,7 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest * This test will fail if it's executed twice * @throws Exception */ - @Test(priority = 27) + @Test(priority = 42) public void testNewDefaultCore() throws Exception { String core = "newDefaultCore"; @@ -472,18 +922,20 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest .withParams("coreName=" + core, "storeRef=" + storeRef, "template=" + template) .withSolrAdminAPI().getAction("newDefaultIndex"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "success"); + + String actionCore = response.getResponse().body().jsonPath().get("action.core"); + Assert.assertEquals(actionCore, core, "Created core name is expected in action.core,"); } /** * When creating a core that already exists, this action fails. * @throws Exception */ - @Test(priority = 28) + @Test(priority = 43) public void testNewDefaultCoreError() throws Exception { String core = "alfresco"; @@ -492,10 +944,9 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest RestResponse response = restClient.withParams("coreName=" + core, "template=" + template) .withSolrAdminAPI().getAction("newDefaultIndex"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); - String actionStatus = response.getResponse().body().jsonPath().get("action.status").toString(); + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); Assert.assertEquals(actionStatus, "error"); } @@ -512,8 +963,11 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest .withParams("coreName=" + core, "storeRef=" + storeRef) .withSolrAdminAPI().getAction("removeCore"); - String status = response.getResponse().body().jsonPath().get("responseHeader.status").toString(); - Assert.assertEquals(status, SOLR_RESPONSE_STATUS_OK); + checkResponseStatusOk(response); + + String actionStatus = response.getResponse().body().jsonPath().get("action.status"); + Assert.assertEquals(actionStatus, "success"); + } } diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoCoreAdminHandler.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoCoreAdminHandler.java index 9f0c64d97..3d5bce192 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoCoreAdminHandler.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoCoreAdminHandler.java @@ -984,18 +984,22 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler * - core, The name of the SOLR Core or "null" to get the report for every core * @return Response including the action result: * - report: An Object with the report details + * - error: When mandatory parameters are not set, an error node is returned * * @throws JSONException */ private NamedList actionNODEREPORTS(SolrParams params) throws JSONException { - Long dbid = - ofNullable(params.get(ARG_NODEID)) - .map(Long::valueOf) - .orElseThrow(() -> new AlfrescoRuntimeException("No dbid parameter set.")); - + NamedList report = new SimpleOrderedMap<>(); + if (params.get(ARG_NODEID) == null) + { + report.add(ACTION_STATUS_ERROR, "No " + ARG_NODEID +" parameter set."); + return report; + } + + Long nodeid = Long.valueOf(params.get(ARG_NODEID)); String requestedCoreName = coreName(params); coreNames().stream() @@ -1006,7 +1010,7 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler .forEach(coreNameAndPublisher -> report.add( coreNameAndPublisher.getFirst(), - buildNodeReport(coreNameAndPublisher.getSecond(), dbid))); + buildNodeReport(coreNameAndPublisher.getSecond(), nodeid))); return report; } @@ -1020,18 +1024,21 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler * - core, The name of the SOLR Core or "null" to get the report for every core * @return Response including the action result: * - report: an Object with the details of the report - * + * - error: When mandatory parameters are not set, an error node is returned + * * @throws JSONException */ private NamedList actionACLREPORT(SolrParams params) throws JSONException { - Long aclid = - ofNullable(params.get(ARG_ACLID)) - .map(Long::valueOf) - .orElseThrow(() -> new AlfrescoRuntimeException("No " + ARG_ACLID + " parameter set.")); - NamedList report = new SimpleOrderedMap<>(); + if (params.get(ARG_ACLID) == null) + { + report.add(ACTION_STATUS_ERROR, "No " + ARG_ACLID + " parameter set."); + return report; + } + + Long aclid = Long.valueOf(params.get(ARG_ACLID)); String requestedCoreName = coreName(params); coreNames().stream() @@ -1062,32 +1069,43 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler * - core, The name of the SOLR Core or "null" to get the report for every core * @return Response including the action result: * - report: an Object with the details of the report + * - error: When mandatory parameters are not set, an error node is returned * * @throws JSONException */ private NamedList actionTXREPORT(SolrParams params) throws JSONException { - String coreName = - ofNullable(coreName(params)) - .orElseThrow(() -> new AlfrescoRuntimeException("No " + CoreAdminParams.CORE + " parameter set.")); - NamedList report = new SimpleOrderedMap<>(); - - if (isMasterOrStandalone(coreName)) + + if (params.get(ARG_TXID) == null) { - MetadataTracker tracker = trackerRegistry.getTrackerForCore(coreName, MetadataTracker.class); - Long txid = - ofNullable(params.get(ARG_TXID)) - .map(Long::valueOf) - .orElseThrow(() -> new AlfrescoRuntimeException("No " + ARG_TXID + " parameter set.")); - - report.add(coreName, buildTxReport(trackerRegistry, informationServers.get(coreName), coreName, tracker, txid)); + report.add(ACTION_STATUS_ERROR, "No " + ARG_TXID + " parameter set."); + return report; } - else + + Long txid = Long.valueOf(params.get(ARG_TXID)); + String requestedCoreName = coreName(params); + + coreNames().stream() + .filter(coreName -> requestedCoreName == null || coreName.equals(requestedCoreName)) + .map(coreName -> new Pair<>(coreName, trackerRegistry.getTrackerForCore(coreName, MetadataTracker.class))) + .filter(coreNameAndMetadataTracker -> coreNameAndMetadataTracker.getSecond() != null) + .forEach(coreNameAndMetadataTracker -> + report.add( + coreNameAndMetadataTracker.getFirst(), + buildTxReport( + trackerRegistry, + informationServers.get(coreNameAndMetadataTracker.getFirst()), + coreNameAndMetadataTracker.getFirst(), + coreNameAndMetadataTracker.getSecond(), + txid))); + + if (report.size() == 0) { addAlertMessage(report); } return report; + } /** @@ -1100,18 +1118,21 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler * - acltxid, mandatory, the number of the ACL TX Id to build the report * @return Response including the action result: * - report: an Object with the details of the report + * - error: When mandatory parameters are not set, an error node is returned * * @throws JSONException */ private NamedList actionACLTXREPORT(SolrParams params) throws JSONException { - Long acltxid = - ofNullable(params.get(ARG_ACLTXID)) - .map(Long::valueOf) - .orElseThrow(() -> new AlfrescoRuntimeException("No " + ARG_ACLTXID + " parameter set.")); - NamedList report = new SimpleOrderedMap<>(); + + if (params.get(ARG_ACLTXID) == null) + { + report.add(ACTION_STATUS_ERROR, "No " + ARG_ACLTXID + " parameter set."); + return report; + } + Long acltxid = Long.valueOf(params.get(ARG_ACLTXID)); String requestedCoreName = coreName(params); coreNames().stream() @@ -1145,17 +1166,21 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler * - core, The name of the SOLR Core * @return Response including the action result: * - report: An Object with the report details + * - error: When mandatory parameters are not set, an error node is returned * * @throws IOException */ private NamedList rangeCheck(SolrParams params) throws IOException { - String coreName = - ofNullable(coreName(params)) - .orElseThrow(() -> new AlfrescoRuntimeException("No " + CoreAdminParams.CORE + " parameter set.")); - NamedList response = new SimpleOrderedMap<>(); + String coreName = coreName(params); + if (coreName == null) + { + response.add(ACTION_STATUS_ERROR, "No " + CoreAdminParams.CORE + " parameter set."); + return response; + } + if (isMasterOrStandalone(coreName)) { InformationServer informationServer = informationServers.get(coreName); @@ -1235,7 +1260,7 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler else { response.add("expand", -1); - response.add("exception", "ERROR: Wrong document router type:"+docRouter.getClass().getSimpleName()); + response.add("exception", "ERROR: Wrong document router type:" + docRouter.getClass().getSimpleName()); } } else @@ -1257,17 +1282,21 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler * @return Response including the action result: * - expand: The number of the new End Range limit or -1 if the action failed * - exception: Error message if expand is -1 + * - error: When mandatory parameters are not set, an error node is returned * * @throws IOException */ private synchronized NamedList expand(SolrParams params) throws IOException { - String coreName = - ofNullable(coreName(params)) - .orElseThrow(() -> new AlfrescoRuntimeException("No " + CoreAdminParams.CORE + " parameter set.")); - NamedList response = new SimpleOrderedMap<>(); + String coreName = coreName(params); + if (coreName == null) + { + response.add(ACTION_STATUS_ERROR, "No " + CoreAdminParams.CORE + " parameter set."); + return response; + } + if (isMasterOrStandalone(coreName)) { InformationServer informationServer = informationServers.get(coreName); diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoCoreAdminHandlerIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoCoreAdminHandlerIT.java index 6703bdde5..83abaec9b 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoCoreAdminHandlerIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoCoreAdminHandlerIT.java @@ -290,23 +290,6 @@ public class AlfrescoCoreAdminHandlerIT when(params.get(CoreAdminParams.ACTION)).thenReturn(TXREPORT); when(params.get(CoreAdminParams.CORE)).thenReturn(CORE_NAME); when(params.get(ARG_TXID)).thenReturn(TX_ID); - // Set up the mock ACL tracker. - when(trackerRegistry.getTrackerForCore(CORE_NAME, AclTracker.class)).thenReturn(aclTracker); - when(aclTracker.checkIndex(Long.valueOf(TX_ID), 0L, null, null)).thenReturn(indexHealthReport); - when(indexHealthReport.getDuplicatedAclTxInIndex()).thenReturn(iOpenBitSet); - when(indexHealthReport.getAclTxInIndexButNotInDb()).thenReturn(iOpenBitSet); - when(indexHealthReport.getMissingAclTxFromIndex()).thenReturn(iOpenBitSet); - when(aclTracker.getTrackerState()).thenReturn(trackerState); - // Set up the mock metadata tracker. - when(trackerRegistry.getTrackerForCore(CORE_NAME, MetadataTracker.class)).thenReturn(metadataTracker); - when(metadataTracker.checkIndex(Long.valueOf(TX_ID), 0L, null, null)).thenReturn(metaReport); - when(metaReport.getDuplicatedTxInIndex()).thenReturn(iOpenBitSet); - when(metaReport.getTxInIndexButNotInDb()).thenReturn(iOpenBitSet); - when(metaReport.getMissingTxFromIndex()).thenReturn(iOpenBitSet); - when(metaReport.getDuplicatedLeafInIndex()).thenReturn(iOpenBitSet); - when(metaReport.getDuplicatedErrorInIndex()).thenReturn(iOpenBitSet); - when(metaReport.getDuplicatedUnindexedInIndex()).thenReturn(iOpenBitSet); - when(metadataTracker.getTrackerState()).thenReturn(trackerState); // Call the method under test. alfrescoCoreAdminHandler.handleCustomAction(req, rsp); @@ -315,24 +298,27 @@ public class AlfrescoCoreAdminHandlerIT verify(rsp).add(eq("report"), any(NamedList.class)); } - /** Check that when the transaction id is missing we get an exception. */ - @Test(expected = SolrException.class) + /** Check that when the transaction id is missing we get an error message. */ + @Test public void handleCustomActionTXReportMissingTXId() { when(params.get(CoreAdminParams.ACTION)).thenReturn(TXREPORT); alfrescoCoreAdminHandler.handleCustomAction(req, rsp); - verify(rsp, never()).add(anyString(), any()); + verify(rsp).add(eq("report"), any(NamedList.class)); } - /** Check that when the core name is missing we get an exception. */ - @Test(expected = SolrException.class) + /** Check that when the core name is missing we get a report for every core. */ + @Test public void handleCustomActionTXReportMissingCoreName() { when(params.get(CoreAdminParams.ACTION)).thenReturn(TXREPORT); when(params.get(CoreAdminParams.CORE)).thenReturn(null); alfrescoCoreAdminHandler.handleCustomAction(req, rsp); + + // Check that a report was generated (don't look at the contents of the report though). + verify(rsp).add(eq("report"), any(NamedList.class)); } /** Check that when an unknown action is provided we don't generate a report. */