public void deployCommandsOnDefaultTenant() throws BonitaException { APIClient apiClient = new APIClient(); apiClient.login(DEFAULT_TECHNICAL_LOGGER_USERNAME, DEFAULT_TECHNICAL_LOGGER_PASSWORD); ClientEventUtil.deployCommand(apiClient.getSession()); apiClient.logout(); }
/** * Get API to manage portal user profiles. * * @since 7.2 */ public ProfileAPI getProfileAPI() { return getAPI(ProfileAPI.class); }
protected <T> T getAPI(final Class<T> apiClass) { ensureSessionExists(); try { final ClientInterceptor clientInterceptor = new ClientInterceptor(apiClass.getName(), getServerAPI(), session); @SuppressWarnings("unchecked") final T api = (T) Proxy.newProxyInstance(APIAccessor.class.getClassLoader(), new Class[] { apiClass }, clientInterceptor); return api; } catch (ServerAPIException | UnknownAPITypeException e) { throw new IllegalStateException(e.getMessage(), e); } }
/** * Get an implementation instance of the DAO Interface. * * @param daoInterface the interface of the DAO * @return the implementation of the DAO * @throws BusinessObjectDaoCreationException if the factory is not able to instantiate the DAO */ public <T extends BusinessObjectDAO> T getDAO(final Class<T> daoInterface) throws BusinessObjectDaoCreationException { ensureSessionExists(); if (daoInterface == null) { throw new IllegalArgumentException("daoInterface is null"); } if (!daoInterface.isInterface()) { throw new IllegalArgumentException(daoInterface.getName() + " is not an interface"); } Class<T> daoImplClass; try { daoImplClass = loadClass(daoInterface); if (daoImplClass != null) { final Constructor<T> constructor = daoImplClass.getConstructor(APISession.class); return constructor.newInstance(session); } } catch (final ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalArgumentException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new BusinessObjectDaoCreationException(e); } throw new BusinessObjectDaoCreationException("No Implementation of the DAO available."); }
@Test public void should_create_dao_throw_BusinessObjectDaoCreationException_if_daoImpl_has_no_constructor_with_session() throws Exception { Mockito.doReturn(DummyDAOWithoutConstructorImpl.class).when(client).loadClass(Matchers.any(Class.class)); expectedEx.expect(BusinessObjectDaoCreationException.class); expectedEx.expectMessage(""); client.getDAO(DummyDAO.class); }
/** * This methods serves the purpose to remove confusion between getAPI() when a session is mandatory, and this one, where no session is needed to access the * API class. * * @param apiClass the API to retrieve * @param <T> The type of the API, extending {@link org.bonitasoft.engine.api.LoginAPI} * @return the retrieved API * @throws IllegalStateException if the API cannot be retrieved. */ protected <T extends LoginAPI> T getLoginAPI(Class<T> apiClass) { try { final ClientInterceptor interceptor = new ClientInterceptor(apiClass.getName(), getServerAPI()); @SuppressWarnings("unchecked") final T api = (T) Proxy.newProxyInstance(APIAccessor.class.getClassLoader(), new Class[] { apiClass }, interceptor); return api; } catch (ServerAPIException | UnknownAPITypeException e) { throw new IllegalStateException(e.getMessage(), e); } }
@Test public void should_get_ApplicationAPI_from_server() throws LoginException { client.login(VALID_USERNAME, VALID_PASSWORD); ApplicationAPI api = client.getLivingApplicationAPI(); assertThat(api).isNotNull(); }
@Test public void should_get_BusinessDataAPI_from_server() throws LoginException { client.login(VALID_USERNAME, VALID_PASSWORD); BusinessDataAPI api = client.getBusinessDataAPI(); assertThat(api).isNotNull(); }
@Test public void should_get_CommandAPI_from_server() throws LoginException { client.login(VALID_USERNAME, VALID_PASSWORD); CommandAPI api = client.getCommandAPI(); assertThat(api).isNotNull(); }
@Test public void should_return_session_used_at_creation() throws LoginException, LogoutException { APIClient clientToTest = new APIClient(session); assertThat(clientToTest.getSession()).isEqualTo(session); }
@Test public void should_get_PageAPI_from_server() throws LoginException { client.login(VALID_USERNAME, VALID_PASSWORD); PageAPI api = client.getCustomPageAPI(); assertThat(api).isNotNull(); }
@Test public void should_get_IdentityAPI_from_server() throws LoginException { client.login(VALID_USERNAME, VALID_PASSWORD); IdentityAPI api = client.getIdentityAPI(); assertThat(api).isNotNull(); }
public CommandAPI getCommandAPI() { return getApiClient().getCommandAPI(); }
public PageAPI getPageAPI() { return getApiClient().getCustomPageAPI(); }
public ApplicationAPI getApplicationAPI() { return getApiClient().getLivingApplicationAPI(); }
public BusinessDataAPI getBusinessDataAPI() { return getApiClient().getBusinessDataAPI(); }
public IdentityAPI getIdentityAPI() { return getApiClient().getIdentityAPI(); }
protected <T> T getAPI(final Class<T> apiClass) { ensureSessionExists(); try { final ClientInterceptor clientInterceptor = new ClientInterceptor(apiClass.getName(), getServerAPI(), session); @SuppressWarnings("unchecked") final T api = (T) Proxy.newProxyInstance(APIAccessor.class.getClassLoader(), new Class[] { apiClass }, clientInterceptor); return api; } catch (ServerAPIException | UnknownAPITypeException e) { throw new IllegalStateException(e.getMessage(), e); } }
/** * Get an implementation instance of the DAO Interface. * * @param daoInterface the interface of the DAO * @return the implementation of the DAO * @throws BusinessObjectDaoCreationException if the factory is not able to instantiate the DAO */ public <T extends BusinessObjectDAO> T getDAO(final Class<T> daoInterface) throws BusinessObjectDaoCreationException { ensureSessionExists(); if (daoInterface == null) { throw new IllegalArgumentException("daoInterface is null"); } if (!daoInterface.isInterface()) { throw new IllegalArgumentException(daoInterface.getName() + " is not an interface"); } Class<T> daoImplClass; try { daoImplClass = loadClass(daoInterface); if (daoImplClass != null) { final Constructor<T> constructor = daoImplClass.getConstructor(APISession.class); return constructor.newInstance(session); } } catch (final ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalArgumentException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new BusinessObjectDaoCreationException(e); } throw new BusinessObjectDaoCreationException("No Implementation of the DAO available."); }
@Test public void should_create_dao_throw_BusinessObjectDaoCreationException_if_daoImpl_not_in_classpath() throws Exception { Mockito.doThrow(ClassNotFoundException.class).when(client).loadClass(BusinessObjectDAO.class); expectedEx.expect(BusinessObjectDaoCreationException.class); expectedEx.expectMessage(""); client.getDAO(BusinessObjectDAO.class); }