modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
| 5
modules/enterprise/binding/src/test/java/org/rhq/bindings/TabularWriterTest.java
| 126 ++++------
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertFormatUtility.java
| 3
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
| 12
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/MeasurementMetadataManagerBean.java
| 4
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
| 38 +--
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertManagerBeanTest.java
| 41 ++-
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
| 3
8 files changed, 122 insertions(+), 110 deletions(-)
New commits:
commit e48c0e156bed76588fc884eb2019058906a2e4e5
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue Feb 28 11:22:08 2012 -0500
Ensure the new 'Availability Type' metric is created for both new types
and existing types (in a plugin upgrade).
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/MeasurementMetadataManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/MeasurementMetadataManagerBean.java
index 1432f49..0039aa2 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/MeasurementMetadataManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/MeasurementMetadataManagerBean.java
@@ -58,7 +58,7 @@ public class MeasurementMetadataManagerBean implements
MeasurementMetadataManage
existingType = entityMgr.find(ResourceType.class, existingType.getId());
Set<MeasurementDefinition> existingDefinitions =
existingType.getMetricDefinitions();
- // if necessary insert the mandatory AvailabilityScanPeriod metric
+ // if necessary insert the mandatory AvailabilityType metric
Set<MeasurementDefinition> newTypeMetricDefinitions =
getMetricDefinitions(newType);
if (existingDefinitions.isEmpty()) {
@@ -150,7 +150,7 @@ public class MeasurementMetadataManagerBean implements
MeasurementMetadataManage
// not needed see JBNADM-1639
}
- private Set<MeasurementDefinition> getMetricDefinitions(ResourceType newType)
{
+ public static Set<MeasurementDefinition> getMetricDefinitions(ResourceType
newType) {
Set<MeasurementDefinition> result = newType.getMetricDefinitions();
result = (null == result) ? new HashSet<MeasurementDefinition>(1) :
result;
long period;
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
index 4346f69..f0dc7df 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
@@ -47,8 +47,8 @@ import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.criteria.ResourceCriteria;
import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftDefinitionComparator;
-import org.rhq.core.domain.drift.DriftDefinitionTemplate;
import org.rhq.core.domain.drift.DriftDefinitionComparator.CompareMode;
+import org.rhq.core.domain.drift.DriftDefinitionTemplate;
import org.rhq.core.domain.resource.ProcessScan;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceSubCategory;
@@ -358,8 +358,8 @@ public class ResourceMetadataManagerBean implements
ResourceMetadataManagerLocal
ResourceType existingType;
try {
- existingType =
resourceTypeManager.getResourceTypeByNameAndPlugin(resourceType.getName(), resourceType
- .getPlugin());
+ existingType =
resourceTypeManager.getResourceTypeByNameAndPlugin(resourceType.getName(),
+ resourceType.getPlugin());
} catch (NonUniqueResultException nure) {
log.debug("Found more than one existing ResourceType for " +
resourceType);
// TODO: Delete the redundant ResourceTypes to get the DB into a valid
state.
@@ -576,6 +576,9 @@ public class ResourceMetadataManagerBean implements
ResourceMetadataManagerLocal
// This is a subcategory of our parent where we are supposed to be grouped in.
linkSubCategoryToParents(resourceType);
+ // Ensure that the new type has any built-in metrics (like Availability Type)
+ MeasurementMetadataManagerBean.getMetricDefinitions(resourceType);
+
entityManager.persist(resourceType);
entityManager.flush();
}
@@ -619,8 +622,9 @@ public class ResourceMetadataManagerBean implements
ResourceMetadataManagerLocal
try {
boolean isExistingParent =
originalExistingParentTypes.remove(newParentType);
if (existingType == null || !isExistingParent) {
- ResourceType realParentType = (ResourceType)
entityManager.createNamedQuery(
-
ResourceType.QUERY_FIND_BY_NAME_AND_PLUGIN).setParameter("name",
newParentType.getName())
+ ResourceType realParentType = (ResourceType) entityManager
+ .createNamedQuery(ResourceType.QUERY_FIND_BY_NAME_AND_PLUGIN)
+ .setParameter("name", newParentType.getName())
.setParameter("plugin",
newParentType.getPlugin()).getSingleResult();
ResourceType type = (existingType != null) ? existingType : newType;
if (existingType != null) {
@@ -788,8 +792,8 @@ public class ResourceMetadataManagerBean implements
ResourceMetadataManagerLocal
}
// Second, loop over the sub categories that need to be merged and update and
persist them
- List<ResourceSubCategory> mergedSubCategories = new
ArrayList<ResourceSubCategory>(existingType
- .getChildSubCategories());
+ List<ResourceSubCategory> mergedSubCategories = new
ArrayList<ResourceSubCategory>(
+ existingType.getChildSubCategories());
mergedSubCategories.retainAll(subCategoriesFromNewType.values());
for (ResourceSubCategory existingSubCat : mergedSubCategories) {
updateSubCategory(existingSubCat,
subCategoriesFromNewType.get(existingSubCat.getName()));
@@ -836,19 +840,19 @@ public class ResourceMetadataManagerBean implements
ResourceMetadataManagerLocal
}
// Second, loop over the sub categories that need to be merged and update and
persist them
- List<ResourceSubCategory> mergedChildSubCategories = new
ArrayList<ResourceSubCategory>(existingSubCat
- .getChildSubCategories());
+ List<ResourceSubCategory> mergedChildSubCategories = new
ArrayList<ResourceSubCategory>(
+ existingSubCat.getChildSubCategories());
mergedChildSubCategories.retainAll(childSubCategoriesFromNewSubCat.values());
for (ResourceSubCategory existingChildSubCategory : mergedChildSubCategories) {
// recursively update childSubCategory
- updateSubCategory(existingChildSubCategory,
childSubCategoriesFromNewSubCat.get(existingChildSubCategory
- .getName()));
+ updateSubCategory(existingChildSubCategory,
+
childSubCategoriesFromNewSubCat.get(existingChildSubCategory.getName()));
entityManager.merge(existingChildSubCategory);
}
// Persist all new definitions
- List<ResourceSubCategory> newChildSubCategories = new
ArrayList<ResourceSubCategory>(newSubCategory
- .getChildSubCategories());
+ List<ResourceSubCategory> newChildSubCategories = new
ArrayList<ResourceSubCategory>(
+ newSubCategory.getChildSubCategories());
newChildSubCategories.removeAll(existingSubCat.getChildSubCategories());
for (ResourceSubCategory newChildSubCategory : newChildSubCategories) {
log.info("Metadata update: Adding new child SubCategory [" +
newChildSubCategory.getName()
@@ -868,8 +872,8 @@ public class ResourceMetadataManagerBean implements
ResourceMetadataManagerLocal
public void removeObsoleteSubCategories(Subject subject, ResourceType newType,
ResourceType existingType) {
// Remove all definitions that are in the existing type but not in the new type
existingType = entityManager.find(ResourceType.class, existingType.getId());
- List<ResourceSubCategory> removedSubCategories = new
ArrayList<ResourceSubCategory>(existingType
- .getChildSubCategories());
+ List<ResourceSubCategory> removedSubCategories = new
ArrayList<ResourceSubCategory>(
+ existingType.getChildSubCategories());
removedSubCategories.removeAll(newType.getChildSubCategories());
for (ResourceSubCategory removedSubCat : removedSubCategories) {
// remove it from the resourceType too, so we dont try to persist it again
@@ -894,8 +898,8 @@ public class ResourceMetadataManagerBean implements
ResourceMetadataManagerLocal
for (ResourceSubCategory existingSubCat : existingSubCategories) {
// Remove all definitions that are in the existing type but not in the new
type
- List<ResourceSubCategory> removedChildSubCategories = new
ArrayList<ResourceSubCategory>(existingSubCat
- .getChildSubCategories());
+ List<ResourceSubCategory> removedChildSubCategories = new
ArrayList<ResourceSubCategory>(
+ existingSubCat.getChildSubCategories());
List<ResourceSubCategory> newChildSubCategories =
mapOfNewSubCategories.get(existingSubCat.getName())
.getChildSubCategories();
removedChildSubCategories.removeAll(newChildSubCategories);
commit ba9b3f1b35eeb663bdd9ea3f19d43fa865958c40
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue Feb 28 11:21:05 2012 -0500
Update test to make sure our new built-in 'Availability Type' metric
is created for new types.
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
index 7155c3d..835e79e 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
@@ -141,7 +141,8 @@ public class ResourceMetadataManagerBeanTest extends MetadataBeanTest
{
@Test(dependsOnMethods = { "persistNewTypes" }, groups = {
"plugin.metadata", "NewPlugin" })
public void persistMeasurementDefinitions() throws Exception {
- assertResourceTypeAssociationEquals("ServerA", "TestPlugin",
"metricDefinitions", asList("metric1", "metric2"));
+ assertResourceTypeAssociationEquals("ServerA", "TestPlugin",
"metricDefinitions",
+ asList("metric1", "metric2",
"_AvailabilityType_"));
}
@Test(dependsOnMethods = { "persistNewTypes" }, groups = {
"plugin.metadata", "NewPlugin" })
commit 904fccdaf6549ff744938e1f4b408333e4e2e940
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Feb 27 17:10:04 2012 -0500
Fix db-upgrade format
diff --git a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
index 82befc8..d945358 100644
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@ -3996,9 +3996,10 @@
SET AVAILABILITY_TYPE = 2
WHERE AVAILABILITY_TYPE IS NULL
</statement>
- <schema-alterColumn table="RHQ_AVAILABILITY"
column="AVAILABILITY_TYPE" nullable="FALSE"/>
- <schema-alterColumn table="RHQ_RESOURCE_AVAIL"
column="AVAILABILITY_TYPE" nullable="FALSE"/>
</schema-directSQL>
+
+ <schema-alterColumn table="RHQ_AVAILABILITY"
column="AVAILABILITY_TYPE" nullable="FALSE"/>
+ <schema-alterColumn table="RHQ_RESOURCE_AVAIL"
column="AVAILABILITY_TYPE" nullable="FALSE"/>
</schemaSpec>
commit 4aab6f7abed90450842339e7a999e06cba5c74f5
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Feb 27 16:53:38 2012 -0500
Fix some new avail formatting for pretty print
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
index c75f804..3717ee5 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
@@ -824,9 +824,6 @@ public class AlertManagerBean implements AlertManagerLocal,
AlertManagerRemote {
AlertConditionCategory category = condition.getCategory();
switch (category) {
case AVAILABILITY: {
- // TODO I18N
- str.append("Availability Change To");
- str.append(" [");
AlertConditionOperator operator =
AlertConditionOperator.valueOf(condition.getName().toUpperCase());
String msg;
switch (operator) {
@@ -853,14 +850,11 @@ public class AlertManagerBean implements AlertManagerLocal,
AlertManagerRemote {
break;
}
str.append(AlertI18NFactory.getMessage(msg));
- str.append("]");
break;
}
case AVAIL_DURATION: {
- // TODO I18N
- str.append("Availability Duration ");
AlertConditionOperator operator =
AlertConditionOperator.valueOf(condition.getName().toUpperCase());
String msg;
switch (operator) {
@@ -875,10 +869,10 @@ public class AlertManagerBean implements AlertManagerLocal,
AlertManagerRemote {
break;
}
str.append(AlertI18NFactory.getMessage(msg));
- str.append(" ");
+ str.append(" [");
- double value = condition.getThreshold();
- String formatted = MeasurementConverter.format(value,
MeasurementUnits.MINUTES, false);
+ String value = condition.getOption();
+ String formatted = MeasurementConverter.format(value,
MeasurementUnits.MINUTES);
str.append(formatted);
str.append("]");
commit 20ef1d8bdb17afcdabc3375035e9f4f5a151ab00
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Feb 27 16:53:07 2012 -0500
Update tests to handle some avail changes and also add new avail
category and condition types.
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertManagerBeanTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertManagerBeanTest.java
index a4fe4b4..6cae5f9 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertManagerBeanTest.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertManagerBeanTest.java
@@ -9,8 +9,8 @@ import org.rhq.core.domain.alert.Alert;
import org.rhq.core.domain.alert.AlertCondition;
import org.rhq.core.domain.alert.AlertConditionCategory;
import org.rhq.core.domain.alert.AlertConditionLog;
+import org.rhq.core.domain.alert.AlertConditionOperator;
import org.rhq.core.domain.event.EventSeverity;
-import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.DataType;
import org.rhq.core.domain.measurement.MeasurementDefinition;
import org.rhq.core.domain.measurement.MeasurementUnits;
@@ -26,19 +26,50 @@ public class AlertManagerBeanTest {
private String pretty;
public void testPrettyPrintAVAILABILITY() {
- AlertCondition condition = createCondition(AlertConditionCategory.AVAILABILITY,
null, null, null,
- AvailabilityType.UP.name(), null);
+ AlertCondition condition = createCondition(AlertConditionCategory.AVAILABILITY,
+ AlertConditionOperator.AVAIL_GOES_UP.name(), null, null, null, null);
pretty = getPrettyAlertConditionString(condition);
assert "Availability goes UP".equals(pretty) : pretty;
pretty = getShortPrettyAlertConditionString(condition);
assert "Avail goes UP".equals(pretty) : pretty;
- condition = createCondition(AlertConditionCategory.AVAILABILITY, null, null,
null,
- AvailabilityType.DOWN.name(), null);
+ condition = createCondition(AlertConditionCategory.AVAILABILITY,
AlertConditionOperator.AVAIL_GOES_DOWN.name(),
+ null, null, null, null);
pretty = getPrettyAlertConditionString(condition);
assert "Availability goes DOWN".equals(pretty) : pretty;
pretty = getShortPrettyAlertConditionString(condition);
assert "Avail goes DOWN".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.AVAILABILITY,
+ AlertConditionOperator.AVAIL_GOES_DISABLED.name(), null, null, null, null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Availability goes DISABLED".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Avail goes DISABLED".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.AVAILABILITY,
+ AlertConditionOperator.AVAIL_GOES_UNKNOWN.name(), null, null, null, null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Availability goes UNKNOWN".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Avail goes UNKNOWN".equals(pretty) : pretty;
+
+ }
+
+ public void testPrettyPrintAVAILABILITY_DURATION() {
+ AlertCondition condition =
createCondition(AlertConditionCategory.AVAIL_DURATION,
+ AlertConditionOperator.AVAIL_DURATION_DOWN.name(), null, null, "2",
null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Availability stays DOWN [2m]".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Avail stays DOWN [2m]".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.AVAIL_DURATION,
+ AlertConditionOperator.AVAIL_DURATION_NOT_UP.name(), null, null,
"2", null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Availability stays NOT UP [2m]".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Avail stays NOT UP [2m]".equals(pretty) : pretty;
}
public void testPrettyPrintTHRESHOLD() {
commit 23737de50f6ffab17c19cba29d4d9fa444c1ba67
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Feb 27 16:51:11 2012 -0500
I18N fix
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertFormatUtility.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertFormatUtility.java
index 6d01cb8..80d52d2 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertFormatUtility.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertFormatUtility.java
@@ -78,7 +78,8 @@ public class AlertFormatUtility {
break;
}
case AVAIL_DURATION: {
- str.append("Availability Duration [");
+
str.append(MSG.view_alert_definition_condition_editor_availabilityDuration());
+ str.append(" [");
AlertConditionOperator operator =
AlertConditionOperator.valueOf(condition.getName().toUpperCase());
switch (operator) {
case AVAIL_DURATION_DOWN:
commit 05526b7365cada7e69a0a373c6f79430d395643e
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Feb 27 16:50:45 2012 -0500
Update tests to also pass on Windows
diff --git
a/modules/enterprise/binding/src/test/java/org/rhq/bindings/TabularWriterTest.java
b/modules/enterprise/binding/src/test/java/org/rhq/bindings/TabularWriterTest.java
index a69f7bf..2390b38 100644
--- a/modules/enterprise/binding/src/test/java/org/rhq/bindings/TabularWriterTest.java
+++ b/modules/enterprise/binding/src/test/java/org/rhq/bindings/TabularWriterTest.java
@@ -25,6 +25,7 @@ package org.rhq.bindings;
import static org.testng.Assert.assertEquals;
+import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
@@ -62,10 +63,10 @@ public class TabularWriterTest {
writer.print(users);
- assertLineEquals(1, "id password username", "Cannot print entity
array header");
+ assertLineEquals(1, "id password username", "Cannot print entity
array header", false);
// skip line 2 - its the separator "--------------"
- assertLineEquals(3, "1 rhqadmin rhqadmin", "Cannot print first
entity array item");
- assertLineEquals(4, "222 pw name ", "Cannot print second
entity array item");
+ assertLineEquals(3, "1 rhqadmin rhqadmin", "Cannot print first
entity array item", false);
+ assertLineEquals(4, "222 pw name ", "Cannot print second
entity array item", false);
}
/**
@@ -78,8 +79,8 @@ public class TabularWriterTest {
writer.print(obj);
// first two lines are the header and "----" separator
- assertLineEquals(3, "first string ", "Cannot print first string
array item");
- assertLineEquals(4, "second string", "Cannot print first string
array item");
+ assertLineEquals(3, "first string ", "Cannot print first string
array item", false);
+ assertLineEquals(4, "second string", "Cannot print first string
array item", false);
}
/**
@@ -91,7 +92,8 @@ public class TabularWriterTest {
Object obj = objArray;
writer.print(obj);
- String expected = "Array of java.lang.Integer\n123\n789\n";
+ String term = (File.separatorChar == '/') ? "\n" :
"\r\n";
+ String expected = "Array of java.lang.Integer" + term + "123"
+ term + "789" + term;
String actual = stringWriter.toString();
assertEquals(actual, expected, "Could not print an object Integer
array");
}
@@ -105,7 +107,8 @@ public class TabularWriterTest {
Object obj = primitiveArray;
writer.print(obj);
- String expected = "Array of byte\n" + (int) 'a' + '\n'
+ (int) 'b' + '\n' + (int) 'c' + '\n';
+ String term = (File.separatorChar == '/') ? "\n" :
"\r\n";
+ String expected = "Array of byte" + term + (int) 'a' + term +
(int) 'b' + term + (int) 'c' + term;
String actual = stringWriter.toString();
assertEquals(actual, expected, "Could not print a primitive byte
array");
}
@@ -116,7 +119,7 @@ public class TabularWriterTest {
writer.print(value);
- String expected = "1\n";
+ String expected = (File.separatorChar == '/') ? "1\n" :
"1\r\n";
String actual = stringWriter.toString();
assertEquals(actual, expected, "A byte or Byte should have its value printed
as a String");
@@ -128,7 +131,7 @@ public class TabularWriterTest {
writer.print(value);
- String expected = "1\n";
+ String expected = (File.separatorChar == '/') ? "1\n" :
"1\r\n";
String actual = stringWriter.toString();
assertEquals(actual, expected, "An int or Integer should have its value
printed as a String");
@@ -141,7 +144,8 @@ public class TabularWriterTest {
writer.print(user);
assertNumberOfLinesPrintedIs(4);
- assertLineEquals(0, user.getClass().getSimpleName() + ":", "The
simple class name should be the first line printed");
+ assertLineEquals(0, user.getClass().getSimpleName() + ":",
+ "The simple class name should be the first line printed");
}
@Test
@@ -166,12 +170,14 @@ public class TabularWriterTest {
int passwordLineNumber = 2;
String expectedPasswordLine = "\tpassword: " + user.getPassword();
- assertLineEquals(passwordLineNumber, expectedPasswordLine, "The password
property should be the 3rd line printed");
+ assertLineEquals(passwordLineNumber, expectedPasswordLine,
+ "The password property should be the 3rd line printed");
int usernameLineNumber = 3;
String expectedUsernameLine = "\tusername: " + user.getUsername();
- assertLineEquals(usernameLineNumber, expectedUsernameLine, "The username
property should be the 4th line printed");
+ assertLineEquals(usernameLineNumber, expectedUsernameLine,
+ "The username property should be the 4th line printed");
}
@Test
@@ -187,7 +193,8 @@ public class TabularWriterTest {
assertLineEquals(lineNumber, expectedLine, "The manager property should be
the 3rd line printed");
}
- @Test(enabled = false) // TODO revisit
+ @Test(enabled = false)
+ // TODO revisit
public void oneToManyAssociationShouldPrintForEntity() {
User employee = new User(1, "rhq", "rhq");
@@ -199,8 +206,8 @@ public class TabularWriterTest {
int lineNumber = 2;
String expectedLine = "\temployees: " + company.getEmployees();
- assertLineEquals(lineNumber, expectedLine, "The employees property should be
the 2nd line printed and the " +
- "toString() value of the collection should be displayed.");
+ assertLineEquals(lineNumber, expectedLine, "The employees property should be
the 2nd line printed and the "
+ + "toString() value of the collection should be displayed.");
}
@Test
@@ -209,11 +216,8 @@ public class TabularWriterTest {
writer.print(resource);
- assertLineEquals(
- 1,
- "\t" + padResourceField("id") + ": " +
resource.getId(),
- "Expected Resource.id to be the first property printed."
- );
+ assertLineEquals(1, "\t" + padResourceField("id") + ":
" + resource.getId(),
+ "Expected Resource.id to be the first property printed.");
}
@Test
@@ -222,11 +226,8 @@ public class TabularWriterTest {
writer.print(resource);
- assertLineEquals(
- 2,
- "\t" + padResourceField("name") + ": " +
resource.getName(),
- "Expected Resource.name to be second property printed"
- );
+ assertLineEquals(2, "\t" + padResourceField("name") + ":
" + resource.getName(),
+ "Expected Resource.name to be second property printed");
}
@Test
@@ -235,11 +236,8 @@ public class TabularWriterTest {
writer.print(resource);
- assertLineEquals(
- 3,
- "\t" + padResourceField("version") + ": " +
resource.getVersion(),
- "Expected Resource.version to be third property printed"
- );
+ assertLineEquals(3, "\t" + padResourceField("version") +
": " + resource.getVersion(),
+ "Expected Resource.version to be third property printed");
}
@Test
@@ -248,11 +246,9 @@ public class TabularWriterTest {
writer.print(resource);
- assertLineEquals(
- 4,
- "\t" + padResourceField("currentAvailability") + ":
" + resource.getCurrentAvailability().getAvailabilityType(),
- "Expected short version of Resource.currentAvailability to be fourth
property printed"
- );
+ assertLineEquals(4, "\t" +
padResourceField("currentAvailability") + ": "
+ + resource.getCurrentAvailability().getAvailabilityType(),
+ "Expected short version of Resource.currentAvailability to be fourth
property printed");
}
@Test
@@ -261,11 +257,8 @@ public class TabularWriterTest {
writer.print(resource);
- assertLineEquals(
- 4,
- "\t" + padResourceField("currentAvailability") + ":
",
- "Expected to see empty string for Resource.currentAvailability when
property is null"
- );
+ assertLineEquals(4, "\t" +
padResourceField("currentAvailability") + ": ",
+ "Expected to see empty string for Resource.currentAvailability when
property is null");
}
@Test
@@ -274,47 +267,26 @@ public class TabularWriterTest {
writer.print(resource);
- assertLineEquals(
- 5,
- "\t" + padResourceField("resourceType") + ": "
+ resource.getResourceType().getName(),
- "Expected short version of Resource.resourceType to be the fifth
property printed"
- );
+ assertLineEquals(5, "\t" + padResourceField("resourceType") +
": " + resource.getResourceType().getName(),
+ "Expected short version of Resource.resourceType to be the fifth
property printed");
}
private Resource createResource() {
- return new ResourceBuilder().createServer()
- .usingDefaultResourceType()
- .withId(111)
- .withName("test-server")
- .withUuid("12345")
- .withVersion("1.0")
- .inInventory()
- .withCurrentAvailability(AvailabilityType.UP)
- .build();
+ return new
ResourceBuilder().createServer().usingDefaultResourceType().withId(111).withName("test-server")
+
.withUuid("12345").withVersion("1.0").inInventory().withCurrentAvailability(AvailabilityType.UP).build();
}
private Resource createUncommittedResource() {
- return new ResourceBuilder().createServer()
- .usingDefaultResourceType()
- .withId(111)
- .withName("test-server")
- .withUuid("12345")
- .withVersion("1.0")
- .notInInventory()
- .build();
+ return new
ResourceBuilder().createServer().usingDefaultResourceType().withId(111).withName("test-server")
+
.withUuid("12345").withVersion("1.0").notInInventory().build();
}
@Test
public void printCollectionOfUncommittedResource() {
- Resource parent = new ResourceBuilder().createServer()
- .usingDefaultResourceType()
- .withName("test-server")
- .withUuid("12345")
- .withVersion("1.0")
- .inInventory()
- .with(2).randomChildServices()
-// .notInInventory()
-// .included()
+ Resource parent = new
ResourceBuilder().createServer().usingDefaultResourceType().withName("test-server")
+
.withUuid("12345").withVersion("1.0").inInventory().with(2).randomChildServices()
+ // .notInInventory()
+ // .included()
.build();
writer.print(parent.getChildResources());
@@ -322,13 +294,21 @@ public class TabularWriterTest {
void assertNumberOfLinesPrintedIs(int expectedNumberOfLines) {
String lines[] = getLines();
- assertEquals(lines.length, expectedNumberOfLines, "The actual lines printed
were\n[\n" +
- stringWriter.toString() + "\n]");
+ assertEquals(lines.length, expectedNumberOfLines,
+ "The actual lines printed were\n[\n" + stringWriter.toString() +
"\n]");
}
void assertLineEquals(int lineNumber, String expectedLine, String msg) {
+ assertLineEquals(lineNumber, expectedLine, msg, true);
+ }
+
+ void assertLineEquals(int lineNumber, String expectedLine, String msg, boolean addCR)
{
String actualLine = getLines()[lineNumber];
+ if (addCR) {
+ expectedLine = (File.separatorChar == '/') ? expectedLine :
(expectedLine + "\r");
+ }
+
assertEquals(actualLine, expectedLine, msg + " -- The actual output was
\n[\n" + stringWriter + "\n].");
}