Search in sources :

Example 1 with TenantContext

use of com.icthh.xm.commons.tenant.TenantContext in project xm-ms-entity by xm-online.

the class XmEntitySpecServiceUnitTest method init.

@Before
@SneakyThrows
public void init() {
    TenantContext tenantContext = mock(TenantContext.class);
    when(tenantContext.getTenantKey()).thenReturn(Optional.of(TenantKey.valueOf(TENANT)));
    tenantContextHolder = mock(TenantContextHolder.class);
    when(tenantContextHolder.getContext()).thenReturn(tenantContext);
    ApplicationProperties ap = new ApplicationProperties();
    ap.setSpecificationPathPattern(URL);
    xmEntitySpecService = createXmEntitySpecService(ap, tenantContextHolder);
}
Also used : TenantContext(com.icthh.xm.commons.tenant.TenantContext) TenantContextHolder(com.icthh.xm.commons.tenant.TenantContextHolder) ApplicationProperties(com.icthh.xm.ms.entity.config.ApplicationProperties) Before(org.junit.Before) SneakyThrows(lombok.SneakyThrows)

Example 2 with TenantContext

use of com.icthh.xm.commons.tenant.TenantContext in project xm-ms-entity by xm-online.

the class TenantInterceptorIntTest method testSuccess.

@Test
// TODO fix when security test will be implemented
@Ignore
public void testSuccess() throws Exception {
    when(auth.getDetails()).thenReturn(details);
    when(details.getDecodedDetails()).thenReturn(ImmutableMap.builder().put("tenant", "xm").build());
    lepManager.beginThreadContext(threadContext -> {
        TenantContext tenantContext = mock(TenantContext.class);
        when(tenantContext.getTenantKey()).thenReturn(Optional.of(TenantKey.valueOf("xm")));
        threadContext.setValue(THREAD_CONTEXT_KEY_TENANT_CONTEXT, tenantContext);
        threadContext.setValue(THREAD_CONTEXT_KEY_AUTH_CONTEXT, mock(XmAuthenticationContext.class));
    });
    try {
        // Create the XmEntity
        restXmEntityMockMvc.perform(get("/api/xm-entities")).andExpect(status().isOk());
    } finally {
        lepManager.endThreadContext();
    }
}
Also used : XmAuthenticationContext(com.icthh.xm.commons.security.XmAuthenticationContext) TenantContext(com.icthh.xm.commons.tenant.TenantContext) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TenantContext (com.icthh.xm.commons.tenant.TenantContext)2 XmAuthenticationContext (com.icthh.xm.commons.security.XmAuthenticationContext)1 TenantContextHolder (com.icthh.xm.commons.tenant.TenantContextHolder)1 ApplicationProperties (com.icthh.xm.ms.entity.config.ApplicationProperties)1 SneakyThrows (lombok.SneakyThrows)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1