Skip to content

Commit

Permalink
Test for deprecated items in initial objects (MID-4943)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Oct 17, 2018
1 parent 24223ad commit 7f6efb8
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2018 Evolveum
*
* Licensed 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.
*/

package com.evolveum.midpoint.web;

import java.io.File;
import java.io.IOException;

import org.testng.annotations.Test;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.validator.ObjectValidator;
import com.evolveum.midpoint.schema.validator.ValidationItem;
import com.evolveum.midpoint.schema.validator.ValidationResult;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

/**
* Test that initial objects are parseable, correct, that they are not deprecated and so on.
*
* @author Radovan Semancik
*/
public class TestInitialObjects extends AbstractGuiUnitTest {

private static final Trace LOGGER = TraceManager.getTrace(TestInitialObjects.class);

private static final File DIR_INITIAL_OBJECTS = new File("src/main/resources/initial-objects");

@Test
public void testInitialObjects() throws Exception {
final String TEST_NAME = "testInitialObjects";
displayTestTitle(TEST_NAME);

ObjectValidator validator = new ObjectValidator(getPrismContext());
validator.setAllWarnings();

StringBuilder errorsSb = new StringBuilder();

for (File file : DIR_INITIAL_OBJECTS.listFiles()) {
if (file.isFile()) {
try {
testInitialObject(validator, errorsSb, file);
} catch (Throwable e) {
String msg = "Error processing file "+file.getName()+": "+e.getMessage();
LOGGER.error(msg, e);
display(msg, e);
throw e;
}
}
}

if (errorsSb.length() != 0) {
throw new SchemaException(errorsSb.toString());
}
}

private <O extends ObjectType> void testInitialObject(ObjectValidator validator, StringBuilder errorsSb, File file) throws SchemaException, IOException {
PrismObject<O> object = getPrismContext().parseObject(file);
ValidationResult validationResult = validator.validate(object);
if (validationResult.isEmpty()) {
display("Checked "+object+": no warnings");
return;
}
display("Validation warnings for "+object, validationResult);
for (ValidationItem valItem : validationResult.getItems()) {
errorsSb.append(file.getName());
errorsSb.append(" ");
errorsSb.append(object);
errorsSb.append(" ");
valItem.shortDump(errorsSb);
errorsSb.append("\n");
}
}
}
3 changes: 2 additions & 1 deletion gui/admin-gui/testng-unit.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2017 Evolveum
~ Copyright (c) 2010-2018 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
<classes>
<class name="com.evolveum.midpoint.web.TestUnitObjectWrapperFactory"/>
<class name="com.evolveum.midpoint.web.TestDescriptorLoader"/>
<class name="com.evolveum.midpoint.web.TestInitialObjects"/>
</classes>
</test>
</suite>
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.LocalizableMessage;
import com.evolveum.midpoint.util.ShortDumpable;

/**
* @author semancik
*
*/
public class ValidationItem implements DebugDumpable {
public class ValidationItem implements DebugDumpable, ShortDumpable {

private OperationResultStatus status;
private LocalizableMessage message;
Expand Down Expand Up @@ -64,5 +65,30 @@ public String debugDump(int indent) {
DebugUtil.debugDumpWithLabelShortDump(sb, "itemPath", itemPath, indent + 1);
return sb.toString();
}

@Override
public void shortDump(StringBuilder sb) {
if (status != null) {
sb.append(status);
sb.append(" ");
}
if (itemPath != null) {
sb.append(itemPath);
sb.append(" ");
}
if (message != null) {
sb.append(message.getFallbackMessage());
}
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder("ValidationItem(");
shortDump(sb);
sb.append(")");
return sb.toString();
}



}

0 comments on commit 7f6efb8

Please sign in to comment.