Skip to content

Commit

Permalink
MID-8842 ninja, tests cleaned up finally (not counting dist-upgrade m…
Browse files Browse the repository at this point in the history
…ess)
  • Loading branch information
1azyman committed Jun 23, 2023
1 parent b34bcf0 commit d0660ae
Show file tree
Hide file tree
Showing 22 changed files with 306 additions and 543 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private AuditServiceFactory getFactory(Class<AuditServiceFactory> clazz) {
return candidate;
}
}
throw new SystemException("Couldn't find AuditServiceFactory for class " + clazz);
throw new SystemException("Couldn't find AuditServiceFactory for class " + clazz.getName());
}

private String getFactoryClassName(Configuration config) {
Expand Down
25 changes: 0 additions & 25 deletions tools/ninja/src/main/java/com/evolveum/midpoint/ninja/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;

import com.evolveum.midpoint.ninja.impl.ActionStateListener;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.fusesource.jansi.AnsiConsole;
Expand All @@ -37,20 +34,10 @@ public static void main(String[] args) {
new Main().run(args);
}

private ActionStateListener actionStateListener;

private PrintStream out = System.out;

private PrintStream err = System.err;

public ActionStateListener getActionStateListener() {
return actionStateListener;
}

public void setActionStateListener(ActionStateListener actionStateListener) {
this.actionStateListener = actionStateListener;
}

public PrintStream getOut() {
return out;
}
Expand Down Expand Up @@ -118,21 +105,9 @@ protected <T> void run(String[] args) {
context = new NinjaContext(out, err, allOptions, action.getApplicationContextLevel(allOptions));

try {
if (actionStateListener != null) {
actionStateListener.onBeforeInit(context);
}

action.init(context, options);

if (actionStateListener != null) {
actionStateListener.onBeforeExecution(context);
}

action.execute();

if (actionStateListener != null) {
actionStateListener.onAfterExecution(context);
}
} finally {
action.destroy();
}
Expand Down

This file was deleted.

108 changes: 0 additions & 108 deletions tools/ninja/src/test/java/com/evolveum/midpoint/ninja/BaseTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,53 @@
*/
package com.evolveum.midpoint.ninja;

import com.evolveum.midpoint.ninja.impl.ActionStateListener;
import com.evolveum.midpoint.ninja.impl.NinjaContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.repo.api.RepositoryService;
import org.assertj.core.api.Assertions;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import com.evolveum.midpoint.repo.api.RepoAddOptions;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;

import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import org.assertj.core.api.Assertions;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;

public class DeleteRepositoryTest extends BaseTest {

@BeforeClass
public void initMidpointHome() throws Exception {
setupMidpointHome();
}
@ContextConfiguration(locations = "classpath:ctx-ninja-test.xml")
@DirtiesContext
@Listeners({ com.evolveum.midpoint.tools.testng.AlphabeticalMethodInterceptor.class })
public class DeleteRepositoryTest extends NinjaSpringTest {

@Test
public void deleteByOid() throws Exception {
given();

String type = ObjectTypes.ROLE.name();
String oid = SystemObjectsType.ROLE_DELEGATOR.value();
final String oid = SystemObjectsType.ROLE_DELEGATOR.value();

String[] args = new String[] { "-m", getMidpointHome(), "delete", "-o", oid, "-t", type };
RoleType role = new RoleType();
role.setOid(oid);
role.setName(new PolyStringType("delete by oid"));

OperationResult result = new OperationResult("delete by oid");

ActionStateListener listener = new ActionStateListener() {

@Override
public void onBeforeExecution(NinjaContext context) {
RepositoryService repository = context.getRepository();
repository.addObject(role.asPrismObject(), new RepoAddOptions(), result);

try {
PrismObject<?> role = repository.getObject(RoleType.class, oid,
GetOperationOptions.createRawCollection(), result);
when();

Assert.assertNotNull(role);
} catch (Exception ex) {
Assertions.fail("Couldn't find role that should be deleted by ninja", ex);
}
}
executeTest(null, null, "-v", "-m", getMidpointHome(), "delete", "-o", oid, "-t", type);

@Override
public void onAfterExecution(NinjaContext context) {
RepositoryService repository = context.getRepository();
try {
PrismObject<RoleType> role = repository.getObject(RoleType.class, oid, GetOperationOptions.createRawCollection(), result);
then();

Assertions.fail("Get object should fail with object not found exception");
} catch (ObjectNotFoundException ex) {
// ignored
} catch (Exception ex) {
Assertions.fail("Unknown exception", ex);
}
}
};
try {
repository.getObject(RoleType.class, oid, GetOperationOptions.createRawCollection(), result);

executeTest(args, null, null, listener);
Assertions.fail("Get object should fail with object not found exception");
} catch (ObjectNotFoundException ex) {
// ignored
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.ninja.upgrade;
package com.evolveum.midpoint.ninja;

import java.io.File;

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

package com.evolveum.midpoint.ninja;

import com.evolveum.midpoint.ninja.impl.Command;

import org.testng.annotations.Test;

import com.evolveum.midpoint.ninja.impl.Command;

/**
* Created by Viliam Repan (lazyman).
*/
public class HelpTest extends BaseTest {
public class HelpTest implements NinjaTestMixin {

@Test
public void runHelp() throws Exception {
executeTest(new String[] { "-h" }, null, null, null);
executeTest(null, null, "-h");

//todo assert help somehow
}

@Test
public void runHelpForEachCommand() throws Exception {
for (Command command : Command.values()) {
executeTest(new String[] { "-h", command.getCommandName() }, null, null, null);
executeTest(null, null, "-h", command.getCommandName());
}
}
}

0 comments on commit d0660ae

Please sign in to comment.