Search in sources :

Example 1 with MetaDataRepository

use of org.jaffa.rules.meta.MetaDataRepository in project jaffa-framework by jaffa-projects.

the class GenericForeignKeyValidatorTest method setup.

/**
 * Setup all tests.
 */
@Before
public void setup() throws Exception {
    testModel.setUOW(new TestUOW());
    testModel.setField1("Key123");
    // This is what the validator factory would build up.
    MetaDataRepository repo = MetaDataRepository.instance();
    target.setRuleMap(repo.getPropertyRuleMap(TestModel.class.getName(), "generic-foreign-key"));
}
Also used : MetaDataRepository(org.jaffa.rules.meta.MetaDataRepository) Before(org.junit.Before)

Example 2 with MetaDataRepository

use of org.jaffa.rules.meta.MetaDataRepository in project jaffa-framework by jaffa-projects.

the class CxfFunctionGuardInterceptorTest method testInterceptor.

@Test
public void testInterceptor() throws NoSuchMethodException, FrameworkException, ApplicationExceptions {
    // Mock the security manager
    PowerMockito.mockStatic(SecurityManager.class);
    PowerMockito.when(SecurityManager.checkFunctionAccess("Test")).thenReturn(true);
    // Mock the Rule helper factory and the rule it returns
    mockStatic(RuleHelperFactory.class);
    IRuleHelper ruleHelperFactory = mock(IRuleHelper.class);
    when(RuleHelperFactory.instance(Mockito.anyString())).thenReturn(ruleHelperFactory);
    // Mock the metadata repository
    mockStatic(MetaDataRepository.class);
    MetaDataRepository repository = mock(MetaDataRepository.class);
    when(MetaDataRepository.instance()).thenReturn(repository);
    // Create a real instance of an interceptor
    CxfFunctionGuardInterceptor interceptor = new CxfFunctionGuardInterceptor();
    // Successful access - matching method and name
    updateRules("Test", "Test", repository, ruleHelperFactory);
    interceptor.handleMessage(getMockMessage());
    // Failed access - matching method not valid name
    Fault fault = null;
    try {
        updateRules("Fail", "Test", repository, ruleHelperFactory);
        interceptor.handleMessage(getMockMessage());
    } catch (Fault f) {
        fault = f;
    }
    Assert.assertNotNull("Fault should have been thrown du to failed access", fault);
    // Successful access - not matching method, so rules not enforced
    updateRules("xxxxx", "NoMatch", repository, ruleHelperFactory);
    interceptor.handleMessage(getMockMessage());
}
Also used : CxfFunctionGuardInterceptor(org.jaffa.rules.interceptors.CxfFunctionGuardInterceptor) IRuleHelper(org.jaffa.rules.rulemeta.IRuleHelper) MetaDataRepository(org.jaffa.rules.meta.MetaDataRepository) Fault(org.apache.cxf.interceptor.Fault) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with MetaDataRepository

use of org.jaffa.rules.meta.MetaDataRepository in project jaffa-framework by jaffa-projects.

the class PartialForeignKeyValidatorTest method setup.

/**
 * Setup all tests.
 */
@Before
public void setup() throws Exception {
    testModel.setUOW(new TestUOW());
    testModel.setField1("Key123");
    // This is what the validator factory would build up.
    MetaDataRepository repo = MetaDataRepository.instance();
    target.setRuleMap(repo.getPropertyRuleMap(TestModel.class.getName(), "partial-foreign-key"));
}
Also used : MetaDataRepository(org.jaffa.rules.meta.MetaDataRepository) Before(org.junit.Before)

Aggregations

MetaDataRepository (org.jaffa.rules.meta.MetaDataRepository)3 Before (org.junit.Before)2 Fault (org.apache.cxf.interceptor.Fault)1 CxfFunctionGuardInterceptor (org.jaffa.rules.interceptors.CxfFunctionGuardInterceptor)1 IRuleHelper (org.jaffa.rules.rulemeta.IRuleHelper)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1