Skip to content

Commit

Permalink
MID-8842 copied ninja code to support-4.4 (matching d0660ae)
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jun 23, 2023
1 parent 0145d8c commit 5de1e52
Show file tree
Hide file tree
Showing 24 changed files with 369 additions and 725 deletions.
7 changes: 0 additions & 7 deletions tools/ninja/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,6 @@
<artifactId>jakarta.xml.ws-api</artifactId>
</dependency>

<!-- LOGGING -->

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<!-- TEST DEPENDENCIES -->
<dependency>
<groupId>org.springframework</groupId>
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class UpgradeObjectsOptions extends ExportOptions {

public static final String P_VERIFICATION_LONG = "--verification-file";

@ParametersDelegate
private OutputOptions outputOptions = new OutputOptions();

@ParametersDelegate
private SearchOptions searchOptions = new SearchOptions();
// @ParametersDelegate
// private OutputOptions outputOptions = new OutputOptions();
//
// @ParametersDelegate
// private SearchOptions searchOptions = new SearchOptions();

@Parameter(names = { P_VERIFICATION_LONG }, descriptionKey = "upgradeObjects.verification")
private File verification;
Expand All @@ -35,19 +35,19 @@ public void setVerification(File verification) {
this.verification = verification;
}

public OutputOptions getOutputOptions() {
return outputOptions;
}

public void setOutputOptions(OutputOptions outputOptions) {
this.outputOptions = outputOptions;
}

public SearchOptions getSearchOptions() {
return searchOptions;
}

public void setSearchOptions(SearchOptions searchOptions) {
this.searchOptions = searchOptions;
}
// public OutputOptions getOutputOptions() {
// return outputOptions;
// }
//
// public void setOutputOptions(OutputOptions outputOptions) {
// this.outputOptions = outputOptions;
// }
//
// public SearchOptions getSearchOptions() {
// return searchOptions;
// }
//
// public void setSearchOptions(SearchOptions searchOptions) {
// this.searchOptions = searchOptions;
// }
}

This file was deleted.

5 changes: 5 additions & 0 deletions tools/ninja/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,8 @@ upgradeObjects.verification=Verification results file
output.output=Output file path. If file is not defined data will be printed out to SYSOUT.
output.overwrite=Overwrite output file if it exists.
upgradeFiles=Upgrade files
search.raw=Use raw option
search.oid=Object OID
search.type=Object type, case insensitive value, e.g. "user". Do not use "Type" suffix.
search.filter=Value of object filter used to search objects. If you start the filter with the \
letter @, the rest should be a filename. Start the filter with % to use Axiom query language.
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
}
}
}

This file was deleted.

0 comments on commit 5de1e52

Please sign in to comment.