Skip to content

Commit

Permalink
Library funcion midpoint.getConst(), additional tests and test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed May 16, 2017
1 parent cd39294 commit a68c92b
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 13 deletions.
Expand Up @@ -101,7 +101,7 @@ public static void searchClasses(String packageName, Consumer<Class> consumer) {
* destination
* @return successful extraction
*/
public static Boolean extractFileFromClassPath(String src, String dst) {
public static boolean extractFileFromClassPath(String src, String dst) {
InputStream is = ClassPathUtil.class.getClassLoader().getResourceAsStream(src);
if (null == is) {
LOGGER.error("Unable to find file {} for extraction to {}", src, dst);
Expand Down
Expand Up @@ -1078,4 +1078,6 @@ List<ObjectReferenceType> getMembersAsReferences(String orgOid)
String createPasswordResetLink(UserType userType);

String createAccountActivationLink(UserType userType);

String getConst(String name);
}
Expand Up @@ -26,6 +26,7 @@
import com.evolveum.midpoint.model.api.context.ModelElementContext;
import com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision;
import com.evolveum.midpoint.model.api.expr.MidpointFunctions;
import com.evolveum.midpoint.model.common.ConstantsManager;
import com.evolveum.midpoint.model.common.expression.script.ScriptExpressionEvaluationContext;
import com.evolveum.midpoint.model.impl.ModelObjectResolver;
import com.evolveum.midpoint.model.impl.lens.LensContext;
Expand Down Expand Up @@ -123,6 +124,9 @@ public class MidpointFunctionsImpl implements MidpointFunctions {

@Autowired
private WorkflowService workflowService;

@Autowired
private ConstantsManager constantsManager;

public String hello(String name) {
return "Hello "+name;
Expand Down Expand Up @@ -1351,4 +1355,9 @@ private String getNonce(UserType user) {
return null;
}
}

@Override
public String getConst(String name) {
return constantsManager.getConstantValue(name);
}
}
Expand Up @@ -37,6 +37,7 @@
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.FailableRunnable;
import com.evolveum.midpoint.util.Holder;
Expand Down Expand Up @@ -88,6 +89,24 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
repoAddObjectFromFile(USER_GUYBRUSH_FILE, true, initResult);
repoAddObjectFromFile(USER_ELAINE_FILE, true, initResult);
}

@Test
public void test000Sanity() throws Exception {
final String TEST_NAME = "test000Sanity";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);

// WHEN
OperationResult testResult = modelService.testResource(RESOURCE_DUMMY_YELLOW_OID, task);

// THEN
display("Test result", testResult);
assertSuccess(testResult);

assertEquals("Wrong YELLOW useless string", IntegrationTestTools.CONST_USELESS, dummyResourceYellow.getUselessString());
}

@Test
public void test100JackAssignDummyYellow() throws Exception {
Expand Down
Expand Up @@ -50,6 +50,7 @@
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
Expand Down Expand Up @@ -1815,9 +1816,14 @@ public void test300AssignGuybrushDummyYellow() throws Exception {
ACCOUNT_GUYBRUSH_DUMMY_FULLNAME, true);
display("Dummy account", dummyAccount);
assertDummyAccountAttribute(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME,
DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME, "Bla bla bla administrator -- administrator");
DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME,
IntegrationTestTools.CONST_DRINK);
assertDummyAccountAttribute(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME,
DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME,
IntegrationTestTools.CONST_BLABLA + " administrator -- administrator");
assertDummyAccountAttribute(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME,
DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "Some say elaine -- administrator");
DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Some say elaine -- administrator");
}

@Test
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2016 Evolveum
~ Copyright (c) 2010-2017 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 @@ -17,7 +17,8 @@

<!-- yellow resource - almost same as resource-dummy but with strong asIs administrativeStatus mapping
also has a modified synchronization section: just correlation but no reactions.
also it has minimum password length constraint. -->
also it has minimum password length constraint
also it is using some constants in the configuration and expressions. -->

<resource oid="10000000-0000-0000-0000-000000000704"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
Expand Down Expand Up @@ -51,6 +52,11 @@
<icfc:configurationProperties>
<icfi:instanceId>yellow</icfi:instanceId>
<icfi:requireExplicitEnable>true</icfi:requireExplicitEnable>
<icfi:uselessString>
<expression>
<const>useless</const>
</expression>
</icfi:uselessString>
<icfi:uselessGuardedString>
<clearValue>whatever</clearValue>
</icfi:uselessGuardedString>
Expand Down Expand Up @@ -187,7 +193,7 @@
<outbound>
<strength>strong</strength>
<expression>
<value>rum</value>
<const>drink</const>
</expression>
</outbound>
</attribute>
Expand All @@ -200,7 +206,7 @@
<expression>
<script>
<code>
'Bla bla bla ' + midpoint.getPrincipal().getUsername() + ' -- ' + actor?.getName()
midpoint.getConst('blabla') + ' ' + midpoint.getPrincipal().getUsername() + ' -- ' + actor?.getName()
</code>
</script>
</expression>
Expand Down
Expand Up @@ -117,10 +117,6 @@ public class TestUcfOpenDj extends AbstractTestNGSpringContextTests {

protected static OpenDJController openDJController = new OpenDJController();

public TestUcfOpenDj() {
System.setProperty("midpoint.home", "target/midPointHome/");
}

@BeforeSuite
public void setup() throws SchemaException, SAXException, IOException {
PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
Expand Down
57 changes: 57 additions & 0 deletions provisioning/ucf-impl-connid/src/test/resources/logback-test.xml
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2016 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.
-->

<configuration>
<appender name="X" class="ch.qos.logback.core.FileAppender">
<file>./target/test.log</file>
<encoder>
<pattern>%date [%thread] %-5level \(%logger{46}\): %message%n</pattern>
</encoder>
</appender>
<logger name="org.hibernate.engine.jdbc.spi.SqlExceptionHelper" level="ERROR"/>
<logger name="com.evolveum.midpoint" level="TRACE" />
<logger name="com.evolveum.midpoint.provisioning.impl" level="ALL" />
<logger name="com.evolveum.midpoint.repo" level="DEBUG" />
<logger name="com.evolveum.midpoint.util.ClassPathUtil" level="INFO"/>

<!-- Do not change this. Make sure complete ConnId logging is always enabled in
the tests. If there is any bug in ConnId logging this should reveal it. -->
<logger name="org.identityconnectors" level="TRACE" />

<logger name="com.evolveum.polygon" level="TRACE" />
<logger name="com.evolveum.icf" level="TRACE" />
<logger name="org.forgerock.openicf" level="TRACE" />

<logger name="com.evolveum.icf.dummy.resource" level="TRACE"/>

<!-- too loud: DEBUG -->
<logger name="com.evolveum.midpoint.provisioning.impl.ResourceManager" level="DEBUG" />

<!-- WARNING! See also logging.properties. Apache LDAP API logs too much. Therefore it is limited on JUL level. -->
<logger name="org.apache.directory" level="INFO" />
<logger name="org.apache.directory.api.ldap.model.schema.registries" level="INFO" />
<logger name="org.apache.directory.api.ldap.model.schema.parsers" level="INFO" />
<logger name="org.apache.directory.api.asn1" level="INFO" />
<logger name="org.apache.directory.api.CODEC_LOG" level="INFO" />
<logger name="org.apache.directory.api.ldap.codec" level="INFO" />
<logger name="org.apache.directory.CURSOR_LOG" level="INFO" />
<logger name="PROFILING" level="TRACE" />
<root level="INFO">
<appender-ref ref="X" />
</root>
</configuration>

Expand Up @@ -94,6 +94,8 @@ public class IntegrationTestTools {

// Constants from test-config.xml.
public static final String CONST_USELESS = "xUSEless";
public static final String CONST_DRINK = "rum";
public static final String CONST_BLABLA = "Bla bla bla";

public static final String DUMMY_CONNECTOR_TYPE = "com.evolveum.icf.dummy.connector.DummyConnector";
public static final String DBTABLE_CONNECTOR_TYPE = "org.identityconnectors.databasetable.DatabaseTableConnector";
Expand Down
2 changes: 2 additions & 0 deletions repo/repo-test-util/src/main/resources/test-config.xml
Expand Up @@ -59,6 +59,8 @@
</keystore>
<constants>
<useless>xUSEless</useless>
<drink>rum</drink>
<blabla>Bla bla bla</blabla>
</constants>
</midpoint>
</configuration>
Expand Up @@ -191,10 +191,16 @@ private void loadConfiguration(File midpointHome) {
try {
if (!configFile.exists()) {
LOGGER.warn("Configuration file {} does not exists. Need to do extraction ...", configFile);
ClassPathUtil.extractFileFromClassPath(this.getConfigFilename(), configFile.getPath());
boolean success = ClassPathUtil.extractFileFromClassPath(this.getConfigFilename(), configFile.getPath());
if (!success || !configFile.exists()) {
String message = "Unable to extract configuration file " + this.getConfigFilename() + " from classpath";
LOGGER.error(message);
System.out.println(message);
throw new SystemException(message);
}
}
//Load and parse properties
config.addProperty(MIDPOINT_HOME_SYSTEM_PROPERTY_NAME, System.getProperty(MIDPOINT_HOME_SYSTEM_PROPERTY_NAME));
config.addProperty(MIDPOINT_HOME_SYSTEM_PROPERTY_NAME, midPointHomePath);
createXmlConfiguration(documentBuilder, configFile.getPath());
} catch (ConfigurationException e) {
String message = "Unable to read configuration file [" + configFile + "]: " + e.getMessage();
Expand Down

0 comments on commit a68c92b

Please sign in to comment.