http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneEntityRestlet.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneEntityRestlet.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneEntityRestlet.java deleted file mode 100644 index da27d9e..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneEntityRestlet.java +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.polygene.library.restlet; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Consumer; -import org.apache.polygene.api.common.Optional; -import org.apache.polygene.api.entity.EntityComposite; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.injection.scope.Service; -import org.apache.polygene.api.injection.scope.Structure; -import org.apache.polygene.api.injection.scope.Uses; -import org.apache.polygene.api.structure.Module; -import org.apache.polygene.api.unitofwork.NoSuchEntityException; -import org.apache.polygene.api.unitofwork.UnitOfWork; -import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; -import org.apache.polygene.api.usecase.UsecaseBuilder; -import org.apache.polygene.api.value.ValueBuilder; -import org.apache.polygene.api.value.ValueBuilderFactory; -import org.apache.polygene.library.restlet.metainfo.UserIdentity; -import org.apache.polygene.library.restlet.repository.RepositoryLocator; -import org.apache.polygene.library.restlet.resource.DefaultResourceFactoryImpl; -import org.apache.polygene.library.restlet.resource.NotPresentException; -import org.apache.polygene.library.restlet.resource.ResourceFactory; -import org.apache.polygene.library.restlet.resource.ServerResource; -import org.apache.polygene.library.restlet.serialization.PolygeneConverter; -import org.apache.polygene.spi.PolygeneSPI; -import org.restlet.Context; -import org.restlet.Request; -import org.restlet.Response; -import org.restlet.Restlet; -import org.restlet.data.Form; -import org.restlet.data.Method; -import org.restlet.data.Parameter; -import org.restlet.data.Status; -import org.restlet.representation.Representation; -import org.restlet.representation.Variant; -import org.restlet.routing.Router; -import org.restlet.security.User; - -public class PolygeneEntityRestlet<T extends HasIdentity> extends Restlet -{ - /** - * Creates a new PolygeneEntityRestlet instance for the given resource and entity classes. - * <p> - * This utility method should be used in your org.restlet.Application to create routes. - * - * @param <K> Parameterized type of the resource - * @param <T> Parameterized type of the entity - * @param module Module to use for object instanciation - * @param router Restlet Router - * @param resourceClass Resource class - * @param entityClass Entity class - * - * @return The PolygeneEntityRestlet instance - */ - public static <K extends HasIdentity, T extends ServerResource<K>> Restlet newInstance( - Module module, Router router, Class<T> resourceClass, Class<K> entityClass - ) - { - @SuppressWarnings( "unchecked" ) - ResourceFactory<K, T> factory = module.newObject( DefaultResourceFactoryImpl.class, resourceClass, router ); - return module.newObject( PolygeneEntityRestlet.class, factory, router, entityClass, new PolygeneConverter( module ) ); - } - - @Structure - private ValueBuilderFactory vbf; - - @Structure - private UnitOfWorkFactory uowf; - - @Uses - private ResourceFactory resourceFactory; - - @Uses - private Router router; - - @Uses - @Optional - private Class<T> identityType; - - @Structure - private PolygeneSPI spi; - - @Uses - private PolygeneConverter converter; - - @Service - private RepositoryLocator locator; - - @Override - public void handle( Request request, Response response ) - { - try - { - super.handle( request, response ); - Method method = request.getMethod(); - if( method.equals( Method.GET ) ) - { - get( request, response ); - } - if( method.equals( Method.DELETE ) ) - { - delete( request, response ); - } - if( method.equals( Method.POST ) ) - { - post( request, response ); - } - if( method.equals( Method.PUT ) ) - { - put( request, response ); - } - } - catch( RuntimeException e ) - { - e.printStackTrace(); - throw e; - } - } - - private void get( Request request, Response response ) - { - execute( request, response, resource -> { - try - { - T result = resource.get(); - if( result != null ) - { - if( result instanceof EntityComposite ) - { - result = locator.find( identityType ).toValue( result ); - } - Representation representation = converter.toRepresentation( result, new Variant(), null ); - response.setEntity( representation ); - response.setStatus( Status.SUCCESS_OK ); - } - else - { - response.setStatus( Status.CLIENT_ERROR_NOT_FOUND ); - } - } - catch( NoSuchEntityException e ) - { - response.setStatus( Status.CLIENT_ERROR_NOT_FOUND, e, "Entity not found." ); - } - } - ); - } - - private void put( Request request, Response response ) - { - execute( request, response, resource -> { - - T value = convertToObject( identityType, request ); - resource.put( value ); - response.setStatus( Status.SUCCESS_OK ); - } ); - } - - private void delete( Request request, Response response ) - { - execute( request, response, resource -> { - resource.delete(); - response.setStatus( Status.SUCCESS_NO_CONTENT ); - } ); - } - - private void post( final Request request, final Response response ) - { - execute( request, response, resource -> { - RestForm form = createRestForm( request ); - RestLink link = resource.post( form ); - response.setLocationRef( link.path().get() ); - response.setStatus( Status.REDIRECTION_SEE_OTHER ); - } ); - } - - private RestForm createRestForm( final Request request ) - { - //noinspection MismatchedQueryAndUpdateOfCollection - Form form = new Form( request.getEntity() ); - ValueBuilder<RestForm> builder = vbf.newValueBuilderWithState( - RestForm.class, - descriptor -> { - if( descriptor.qualifiedName().name().equals( "fields" ) ) - { - List<FormField> result = new ArrayList<>(); - for( Parameter param : form ) - { - String name = param.getName(); - String value = param.getValue(); - ValueBuilder<FormField> fieldBuilder = vbf.newValueBuilder( FormField.class ); - FormField prototype = fieldBuilder.prototype(); - prototype.name().set( name ); - prototype.value().set( value ); - prototype.type().set( FormField.TEXT ); - result.add( fieldBuilder.newInstance() ); - } - return result; - } - return null; - }, - descriptor -> null, - descriptor -> null, - descriptor -> null - ); - return builder.newInstance(); - } - - private void execute( Request request, Response response, Consumer<ServerResource<T>> closure ) - { - UnitOfWork uow = null; - try - { - uow = createUnitOfWork( request ); - ServerResource<T> resource = createResource( request, response, getContext() ); - closure.accept( resource ); - uow.complete(); - } - catch( UnsupportedOperationException e ) - { - e.printStackTrace(); - response.setStatus( Status.CLIENT_ERROR_BAD_REQUEST, e, e.getMessage() ); - } - catch( ConversionException e ) - { - e.printStackTrace(); - response.setStatus( Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage() ); - } - catch( NotPresentException e ) - { - e.printStackTrace(); - response.setStatus( Status.CLIENT_ERROR_NOT_FOUND, e.getMessage() ); - } - catch( Throwable e ) - { - e.printStackTrace(); - response.setStatus( Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage() ); - } - finally - { - if( uow != null && uow.isOpen() ) - { - uow.discard(); - } - } - } - - private ServerResource<T> createResource( Request request, Response response, Context context ) - { - @SuppressWarnings( "unchecked" ) - ServerResource<T> serverResource = resourceFactory.create( identityType, request, response, context ); - return serverResource; - } - - private UnitOfWork createUnitOfWork( Request request ) - { - UsecaseBuilder usecaseBuilder = UsecaseBuilder.buildUsecase( request.getResourceRef().getIdentifier( true ) ); - User user = request.getClientInfo().getUser(); - if( user != null ) - { - UserIdentity userIdentity = new UserIdentity( user.getIdentifier(), - user.getName(), - user.getEmail(), - user.getFirstName(), - user.getLastName() - ); - usecaseBuilder.withMetaInfo( userIdentity ); - } - return uowf.newUnitOfWork( usecaseBuilder.newUsecase() ); - } - - private <K> K convertToObject( Class<K> type, Request request ) - { - try - { - return converter.toObject( request.getEntity(), type, null ); - } - catch( IOException e ) - { - throw new ConversionException( request.getEntityAsText() ); - } - } - - @Override - public String toString() - { - return "PolygeneRestlet[" + ( identityType == null ? "<null>" : identityType.getSimpleName() ) + ", " + resourceFactory + "]"; - } -}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneRestApplication.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneRestApplication.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneRestApplication.java deleted file mode 100644 index 0bfd614..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneRestApplication.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.polygene.library.restlet; - -import java.io.PrintStream; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.injection.scope.Structure; -import org.apache.polygene.api.object.ObjectFactory; -import org.apache.polygene.api.structure.Application; -import org.apache.polygene.library.restlet.crud.EntityListResource; -import org.apache.polygene.library.restlet.crud.EntityResource; -import org.apache.polygene.library.restlet.resource.CreationResource; -import org.apache.polygene.library.restlet.resource.DefaultResourceFactoryImpl; -import org.apache.polygene.library.restlet.resource.EntryPoint; -import org.apache.polygene.library.restlet.resource.EntryPointResource; -import org.apache.polygene.library.restlet.resource.ResourceFactory; -import org.apache.polygene.library.restlet.resource.ServerResource; -import org.apache.polygene.library.restlet.serialization.PolygeneConverter; -import org.restlet.Component; -import org.restlet.Context; -import org.restlet.Restlet; -import org.restlet.data.ChallengeScheme; -import org.restlet.data.Parameter; -import org.restlet.engine.Engine; -import org.restlet.routing.Filter; -import org.restlet.routing.Router; -import org.restlet.routing.TemplateRoute; -import org.restlet.security.ChallengeAuthenticator; -import org.restlet.security.Enroler; -import org.restlet.security.Verifier; -import org.restlet.util.Series; - -/** - * This class is generic enough to be promoted to Polygene's Restlet Library - */ -@SuppressWarnings( { "WeakerAccess", "unused" } ) -public abstract class PolygeneRestApplication extends org.restlet.Application -{ - @Structure - protected Application polygeneApplication; - - @Structure - protected ObjectFactory objectFactory; - - protected Router router; - protected String basePath; - - protected PolygeneRestApplication( String basePath, Context context ) - { - super( context ); - this.basePath = basePath; - } - - protected void printRoutes( PrintStream out ) - { - router.getRoutes() - .stream() - .map( Object::toString ) - .forEach( out::println ); - } - - @Override - public synchronized void start() - throws Exception - { - setName( polygeneApplication.name() ); - Series<Parameter> parameters = getContext().getParameters(); - String mode = parameters.getFirstValue( "org.apache.polygene.runtime.mode" ); - super.start(); - getLogger().info( "RestApplication successfully started." ); - } - - @Override - public synchronized void stop() - throws Exception - { - super.stop(); - getLogger().info( "RestApplication successfully stopped." ); - } - - @Override - public Restlet createInboundRoot() - { - Context context = getContext(); - Engine.getInstance().getRegisteredConverters().add( new PolygeneConverter( objectFactory ) ); - - if( polygeneApplication.mode() == Application.Mode.development ) - { - setDebugging( true ); - } - router = new Router( context ); - - addRoutes( router ); - router.attach( basePath, newPolygeneRestlet( EntryPointResource.class, EntryPoint.class ) ); - - Verifier verifier = createVerifier(); - Enroler enroler = createEnroler(); - if( verifier == null && enroler == null ) - { - return createInterceptors(new Filter() - { - } ); - } - else - { - ChallengeAuthenticator guard = new ChallengeAuthenticator( context, ChallengeScheme.HTTP_BASIC, getName() + " Realm" ); - - if( verifier != null ) - { - guard.setVerifier( verifier ); - } - - if( enroler != null ) - { - guard.setEnroler( enroler ); - } - return createInterceptors( guard ); - } - } - - private Restlet createInterceptors( Filter guard ) - { - Filter inner = createInnerInterceptor(); - if( inner != null ) - { - inner.setNext( router ); - guard.setNext( inner ); // guard -> interceptor -> router - } - else - { - guard.setNext( router ); // guard -> router - } - inner = guard; // inner = guard - - Filter outer = createOuterInterceptor(); - if( outer != null ) - { - outer.setNext( inner ); // outer -> inner - return outer; - } - return inner; - } - - protected Filter createOuterInterceptor() - { - return null; - } - - protected Filter createInnerInterceptor() - { - return null; - } - - protected Verifier createVerifier() - { - return null; - } - - protected Enroler createEnroler() - { - return null; - } - - protected abstract void addRoutes( Router router ); - - protected void addResourcePath( String name, - Class<? extends HasIdentity> type, - String basePath - ) - { - addResourcePath( name, type, basePath, true, true ); - } - - protected void addResourcePath( String name, - Class<? extends HasIdentity> type, - String basePath, - boolean createLink, - boolean rootRoute - ) - { - if( createLink ) - { - router.attach( basePath + name + "/create", newPolygeneRestlet( CreationResource.class, type ) ); - } - TemplateRoute route = router.attach( basePath + name + "/", newPolygeneRestlet( EntityListResource.class, type ) ); - if( rootRoute ) - { - route.setName( name ); - } - router.attach( basePath + name + "/{id}/", newPolygeneRestlet( EntityResource.class, type ) ); - router.attach( basePath + name + "/{id}/{invoke}", newPolygeneRestlet( EntityResource.class, type ) ); - } - - private <K extends HasIdentity, T extends ServerResource<K>> Restlet newPolygeneRestlet( Class<T> resourceClass, Class<K> entityClass ) - { - - @SuppressWarnings( "unchecked" ) - ResourceFactory<K, T> factory = objectFactory.newObject( DefaultResourceFactoryImpl.class, - resourceClass, router - ); - PolygeneConverter converter = new PolygeneConverter( objectFactory ); - return objectFactory.newObject( PolygeneEntityRestlet.class, - factory, - router, - entityClass, - converter - ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/RestForm.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/RestForm.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/RestForm.java deleted file mode 100644 index 6f6cdfb..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/RestForm.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet; - -import java.util.List; -import org.apache.polygene.api.common.Optional; -import org.apache.polygene.api.mixin.Mixins; -import org.apache.polygene.api.property.Property; -import org.apache.polygene.library.restlet.filters.NameFilter; - -@Mixins( RestForm.Mixin.class ) -public interface RestForm -{ - FormField field( String name ); - - @Optional - Property<RestLink> link(); - - Property<List<FormField>> fields(); - - abstract class Mixin - implements RestForm - { - @Override - public FormField field( String name ) - { - return fields().get().stream().filter( new NameFilter( name ) ).findFirst().orElse( null ); - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityListResource.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityListResource.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityListResource.java deleted file mode 100644 index f397893..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityListResource.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.crud; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.identity.Identity; -import org.apache.polygene.api.injection.scope.Service; -import org.apache.polygene.api.injection.scope.Structure; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.api.mixin.Mixins; -import org.apache.polygene.api.property.Property; -import org.apache.polygene.api.value.ValueBuilder; -import org.apache.polygene.api.value.ValueBuilderFactory; -import org.apache.polygene.library.restlet.FormField; -import org.apache.polygene.library.restlet.RestForm; -import org.apache.polygene.library.restlet.RestLink; -import org.apache.polygene.library.restlet.identity.IdentityManager; -import org.apache.polygene.library.restlet.repository.CrudRepository; -import org.apache.polygene.library.restlet.repository.RepositoryLocator; -import org.apache.polygene.library.restlet.resource.ResourceBuilder; -import org.apache.polygene.library.restlet.resource.ServerResource; -import org.restlet.Request; -import org.restlet.data.Method; -import org.restlet.data.Reference; - -@Mixins( EntityListResource.Mixin.class ) -public interface EntityListResource<T extends HasIdentity> extends ServerResource<EntityList> -{ - abstract class Mixin<T extends HasIdentity> - implements EntityListResource<T> - { - @This - private Parameters<T> parameters; - - @Structure - private ValueBuilderFactory vbf; - - @Service - private ResourceBuilder resourceBuilder; - - @Service - private RepositoryLocator locator; - - @Service - private IdentityManager identityManager; - - @Override - public EntityList get() - { - Property<Request> request = parameters.request(); - Reference base = request.get().getResourceRef(); - String name = "list[" + parameters.entityType().get().getSimpleName() + "]"; - Identity identity = identityManager.generate( EntityListResource.class, name ); - ValueBuilder<EntityList> builder = vbf.newValueBuilder( EntityList.class ); - List<EntityRef> result = getEntityRefs( base ); - EntityList prototype = builder.prototype(); - prototype.identity().set( identity ); - prototype.entities().set( Collections.unmodifiableList( result ) ); - prototype.commands().set( Collections.singletonList( resourceBuilder.createCommand( base ) ) ); - return builder.newInstance(); - } - - @Override - public RestLink post( RestForm form ) - { - FormField nameField = form.field( "name" ); - String name = null; - if( nameField != null ) - { - name = nameField.value().get(); - } - Reference base = parameters.request().get().getResourceRef(); - Class<T> entityType = parameters.entityType().get(); - Identity identity = identityManager.generate(entityType, name); - locator.find( entityType ).create( identity ); - return resourceBuilder.createBaseLink( identity.toString(), base, Method.GET, "Name form" ); - } - - @SuppressWarnings( "unchecked" ) - private List<EntityRef> getEntityRefs( Reference base ) - { - ArrayList result = new ArrayList<>(); - Property<Class<T>> property = parameters.entityType(); - Class<T> entityType = property.get(); - CrudRepository<T> repository = locator.find( entityType ); - Iterable<T> all = repository.findAll(); - Stream<T> stream = StreamSupport.stream( all.spliterator(), false ); - stream - .map( entity -> entity.identity().get() ) - .map( identity -> resourceBuilder.createEntityRef( identity, base ) ) - .forEach( result::add ); - return result; - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityResource.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityResource.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityResource.java deleted file mode 100644 index 3cf9434..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityResource.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.crud; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.time.format.DateTimeFormatter; -import java.time.temporal.TemporalAccessor; -import org.apache.polygene.api.common.Optional; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.identity.StringIdentity; -import org.apache.polygene.api.injection.scope.Service; -import org.apache.polygene.api.injection.scope.Structure; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.api.mixin.Mixins; -import org.apache.polygene.api.property.Property; -import org.apache.polygene.api.value.ValueBuilder; -import org.apache.polygene.api.value.ValueBuilderFactory; -import org.apache.polygene.library.restlet.FormField; -import org.apache.polygene.library.restlet.RestForm; -import org.apache.polygene.library.restlet.RestLink; -import org.apache.polygene.library.restlet.repository.RepositoryLocator; -import org.apache.polygene.library.restlet.resource.ResourceBuilder; -import org.apache.polygene.library.restlet.resource.ServerResource; -import org.restlet.data.Reference; - -@Mixins( EntityResource.Mixin.class ) -public interface EntityResource<T extends HasIdentity> extends ServerResource<T> -{ - interface EntityParam - { - @Optional - Property<String> invoke(); - } - - abstract class Mixin<T extends HasIdentity> - implements EntityResource<T> - { - - @Structure - private ValueBuilderFactory vbf; - - @This - private Parameters<T> parameters; - - @This - private EntityParam entityParam; - - @Service - private RepositoryLocator locator; - - @Service - private ResourceBuilder resourceBuilder; - - @Override - public T get() - { - Class entityType = parameters.entityType().get(); - //noinspection unchecked - return (T) locator.find( entityType ).get( identity() ); - } - - @Override - public void put( T value ) - { - Class<T> entityType = parameters.entityType().get(); - locator.find( entityType ).update( value ); - } - - @Override - public void delete() - { - Class<? extends HasIdentity> entityType = parameters.entityType().get(); - String idOfEntity = parameters.id().get(); - locator.find( entityType ).delete( StringIdentity.identityOf( idOfEntity ) ); - } - - @Override - public RestLink post( RestForm form ) - { - Class<T> type = parameters.entityType().get(); - String methodName = entityParam.invoke().get(); - try - { - Method method = findMethod( type, methodName ); - if( method == null ) // no arg method doesn't exist, look for single arg method - { - throw new IllegalArgumentException( "Method '" + methodName + "' is not present on " + type.getName() ); - } - Class entityType = parameters.entityType().get(); - //noinspection unchecked - T entity = (T) locator.find( entityType ).get( identity() ); - if( method.getParameterCount() == 1 ) - { - Class argType = method.getParameterTypes()[ 0 ]; - Object parameters = createParametersComposite( form, argType ); - method.invoke( entity, parameters ); - } - else - { - method.invoke( entity ); - } - } - catch( Exception e ) - { - String message = e.getMessage(); - while( e instanceof InvocationTargetException ) - { - e = (Exception) ( (InvocationTargetException) e ).getTargetException(); - message = e.getMessage(); - } - throw new RuntimeException( message, e ); - } - Reference base = parameters.request().get().getResourceRef(); - return resourceBuilder.createBaseLink( "", base, org.restlet.data.Method.GET, "" ); - } - - private Object createParametersComposite( RestForm form, Class<?> argType ) - { - ValueBuilder<?> vb = vbf.newValueBuilderWithState( - argType, - descriptor -> { - FormField field = form.field( descriptor.qualifiedName().name() ); - if( field == null ) - { - return null; - } - Class<?> propertyType = descriptor.valueType().primaryType(); - Property<String> value = field.value(); - if( value == null ) - { - return null; - } - return convertPropertyValue( value.get(), propertyType ); - }, - descriptor -> null, - descriptor -> null, - descriptor -> null - ); - return vb.newInstance(); - } - - private Method findMethod( Class<T> type, String methodName ) - { - Method[] methods = type.getMethods(); - Method method = null; - for( Method m : methods ) - { - if( m.getName().equals( methodName ) ) - { - method = m; - break; - } - } - return method; - } - - private Object convertPropertyValue( String input, Class<?> propertyType ) - { - if( propertyType.equals( String.class ) ) - { - return input; - } - if( Integer.class.isAssignableFrom( propertyType ) ) - { - return Integer.parseInt( input ); - } - if( Boolean.class.isAssignableFrom( propertyType ) ) - { - return Boolean.valueOf( input ); - } - if( Double.class.isAssignableFrom( propertyType ) ) - { - return Double.parseDouble( input ); - } - if( Long.class.isAssignableFrom( propertyType ) ) - { - return Long.parseLong( input ); - } - if( Byte.class.isAssignableFrom( propertyType ) ) - { - return Byte.parseByte( input ); - } - if( Short.class.isAssignableFrom( propertyType ) ) - { - return Short.parseShort( input ); - } - if( Float.class.isAssignableFrom( propertyType ) ) - { - return Float.parseFloat( input ); - } - if( Character.class.isAssignableFrom( propertyType ) ) - { - return input.charAt( 0 ); - } - if( TemporalAccessor.class.isAssignableFrom( propertyType ) ) - { - return DateTimeFormatter.ISO_DATE_TIME.parse( input ); - } - return null; - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/CrudRepository.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/CrudRepository.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/CrudRepository.java deleted file mode 100644 index 0fe23b5..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/CrudRepository.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.repository; - -import java.util.function.Predicate; -import org.apache.polygene.api.composite.Composite; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.identity.Identity; -import org.apache.polygene.api.unitofwork.concern.UnitOfWorkPropagation; - -public interface CrudRepository<T extends HasIdentity> -{ - @UnitOfWorkPropagation - void create( @EntityName Identity identityOfEntity ); - - @UnitOfWorkPropagation - T get( @EntityName Identity identityOfEntity ); - - @UnitOfWorkPropagation - void update( T newStateAsValue ); - - @UnitOfWorkPropagation - void delete( @EntityName Identity identityOfEntity ); - - @UnitOfWorkPropagation - Iterable<T> findAll(); - - @UnitOfWorkPropagation - Iterable<T> find( Predicate<Composite> specification ); - - T toValue( T entity ); - -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/SmallCrudRepositoryMixin.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/SmallCrudRepositoryMixin.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/SmallCrudRepositoryMixin.java deleted file mode 100644 index a5b921c..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/SmallCrudRepositoryMixin.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.repository; - -import java.util.function.Predicate; -import org.apache.polygene.api.PolygeneAPI; -import org.apache.polygene.api.composite.Composite; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.identity.Identity; -import org.apache.polygene.api.injection.scope.Service; -import org.apache.polygene.api.injection.scope.Structure; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.api.query.Query; -import org.apache.polygene.api.query.QueryBuilder; -import org.apache.polygene.api.query.QueryBuilderFactory; -import org.apache.polygene.api.service.ServiceComposite; -import org.apache.polygene.api.unitofwork.NoSuchEntityTypeException; -import org.apache.polygene.api.unitofwork.NoSuchEntityException; -import org.apache.polygene.api.unitofwork.UnitOfWork; -import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; -import org.apache.polygene.library.restlet.identity.IdentityManager; - -public class SmallCrudRepositoryMixin<T extends HasIdentity> - implements CrudRepository<T> -{ - @Structure - private UnitOfWorkFactory uowf; - - @Structure - private QueryBuilderFactory qbf; - - @Service - private IdentityManager identityManager; - - private final Class<T> entityType; - - @SuppressWarnings( "unchecked" ) - public SmallCrudRepositoryMixin( @Structure PolygeneAPI api, @This ServiceComposite me ) - { - entityType = api.serviceDescriptorFor( me ).metaInfo( EntityTypeDescriptor.class ).entityType(); - } - - @Override - public void create( Identity identity ) - { - UnitOfWork uow = uowf.currentUnitOfWork(); - uow.newEntity( entityType, identity ); - } - - @Override - public T get( Identity identity ) - { - UnitOfWork uow = uowf.currentUnitOfWork(); - return uow.get( entityType, identity ); - } - - @Override - public void update( T newStateAsValue ) - { - UnitOfWork uow = uowf.currentUnitOfWork(); - - @SuppressWarnings( "unchecked" ) - Class<HasIdentity> type = (Class<HasIdentity>) entityType; - - uow.toEntity( type, newStateAsValue ); //updates the identified entity with the value - } - - @Override - public void delete( Identity identity ) - { - UnitOfWork uow = uowf.currentUnitOfWork(); - try - { - T entity = uow.get( entityType, identity ); - uow.remove( entity ); - } - catch( NoSuchEntityException | NoSuchEntityTypeException e ) - { - throw new IllegalArgumentException( "Entity '" + identity + "' doesn't exist." ); - } - } - - @Override - public Iterable<T> findAll() - { - return find( item -> true ); - } - - @Override - @SuppressWarnings( "unchecked" ) - public Iterable<T> find( Predicate<Composite> specification ) - { - UnitOfWork uow = uowf.currentUnitOfWork(); - QueryBuilder<T> qb = qbf.newQueryBuilder( entityType ); - Query<T> query = uow.newQuery( qb ); - return qbf.newQueryBuilder( entityType ).where( specification ).newQuery( query ); - } - - @Override - public T toValue( T entity ) - { - return uowf.currentUnitOfWork().toValue( entityType, entity ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationParameterized.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationParameterized.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationParameterized.java deleted file mode 100644 index c79c62b..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationParameterized.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.resource; - -public interface CreationParameterized<T> -{ - /** - * Returns the ValueComposite type to be used to parameterize the reosource. - * - * @return A type to instantiate as a ValueComposite - */ - Class<T> parametersType(); - - void parameterize( T parameters ); -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationResource.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationResource.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationResource.java deleted file mode 100644 index cf84933..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationResource.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.resource; - -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.identity.Identity; -import org.apache.polygene.api.injection.scope.Service; -import org.apache.polygene.api.injection.scope.Structure; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.api.mixin.Mixins; -import org.apache.polygene.api.property.PropertyDescriptor; -import org.apache.polygene.api.unitofwork.UnitOfWork; -import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; -import org.apache.polygene.api.value.ValueBuilder; -import org.apache.polygene.api.value.ValueBuilderFactory; -import org.apache.polygene.library.restlet.FormField; -import org.apache.polygene.library.restlet.RestForm; -import org.apache.polygene.library.restlet.RestLink; -import org.apache.polygene.library.restlet.identity.IdentityManager; -import org.apache.polygene.library.restlet.repository.RepositoryLocator; -import org.restlet.data.Method; - -@Mixins( CreationResource.Mixin.class ) -public interface CreationResource<T extends HasIdentity> extends ServerResource<T> -{ - abstract class Mixin<T extends HasIdentity> - implements CreationResource<T> - { - @Structure - private ValueBuilderFactory vbf; - - @Structure - private UnitOfWorkFactory uowf; - - @This - private Parameters<T> parameters; - - @Service - private ResourceBuilder resourceBuilder; - - @Service - private IdentityManager identityManager; - - @Service - private RepositoryLocator locator; - - @Override - public RestLink post( RestForm form ) - { - String name = form.field( "name" ).value().get(); - Class<? extends HasIdentity> entityType = parameters.entityType().get(); - Identity identity = identityManager.generate( entityType, name ); - locator.find( entityType ).create( identity ); - doParameterization( form, entityType, identity ); - return resourceBuilder.createBaseLink( identity.toString(), parameters.request().get().getResourceRef(), Method.GET, "" ); - } - - private <P> void doParameterization( RestForm form, Class entityType, Identity identity ) - { - if( !CreationParameterized.class.isAssignableFrom( entityType ) ) - { - return; - } - @SuppressWarnings( "unchecked" ) - CreationParameterized<P> created = (CreationParameterized<P>) locator.find( entityType ).get( identity ); - P parameterization = createParameterizationValue( form, created ); - created.parameterize( parameterization ); - } - - private <V> V createParameterizationValue( final RestForm form, CreationParameterized<V> created ) - { - Class<V> valueType = created.parametersType(); - ValueBuilder<V> vb = vbf.newValueBuilderWithState( - valueType, - propertyName -> mapField( form, propertyName ), - association -> null, - association -> null, - association -> null - ); - return vb.newInstance(); - } - - private Object mapField( RestForm form, PropertyDescriptor propertyName ) - { - String name = propertyName.qualifiedName().name(); - FormField field = form.field( name ); - if( field == null ) - { - UnitOfWork uow = uowf.currentUnitOfWork(); - String usecase = ""; - if( uow != null ) - { - usecase = uow.usecase().name(); - } - throw new IllegalArgumentException( "Field named '" + name + "' is required and not present in usecase " + usecase ); - } - return field.value().get(); - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPointResource.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPointResource.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPointResource.java deleted file mode 100644 index 3efcc2e..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPointResource.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.resource; - -import java.util.HashMap; -import java.util.Map; -import org.apache.polygene.api.identity.StringIdentity; -import org.apache.polygene.api.injection.scope.Service; -import org.apache.polygene.api.injection.scope.Structure; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.api.mixin.Mixins; -import org.apache.polygene.api.value.ValueBuilder; -import org.apache.polygene.api.value.ValueBuilderFactory; -import org.apache.polygene.library.restlet.RestLink; -import org.restlet.data.Method; -import org.restlet.data.Reference; -import org.restlet.routing.Route; -import org.restlet.routing.Template; -import org.restlet.routing.TemplateRoute; - -@Mixins( EntryPointResource.Mixin.class ) -public interface EntryPointResource extends ServerResource<EntryPoint> -{ - abstract class Mixin - implements EntryPointResource - { - @This - private Parameters<EntryPoint> parameters; - - @Service - private ResourceBuilder resourceBuilder; - - @Structure - private ValueBuilderFactory vbf; - - private EntryPoint entryPoint; - - @Override - public EntryPoint get() - { - if( entryPoint == null ) - { - entryPoint = createEntryPoint(); - } - return entryPoint; - } - - private EntryPoint createEntryPoint() - { - Map<String, RestLink> entryPoints = new HashMap<>(); - for( Route r : parameters.router().get().getRoutes() ) - { - if( r instanceof TemplateRoute) - { - TemplateRoute route = (TemplateRoute) r; - Template template = route.getTemplate(); - // Only include patterns that doesn't have variables, and has a proper name. - if( template.getVariableNames().isEmpty() && route.getName().indexOf( '>' ) == -1 ) - { - Reference hostRef = parameters.request().get().getOriginalRef(); -// Reference reference = new Reference( hostRef, template.getPattern() ); - RestLink link; - String description = route.getDescription(); - if( description == null ) - { - description = ""; - } - link = resourceBuilder.createLeafLink( template.getPattern(), hostRef, Method.GET, description ); - entryPoints.put( route.getName(), link ); - } - } - } - ValueBuilder<EntryPoint> builder = vbf.newValueBuilder( EntryPoint.class ); - builder.prototype().identity().set( StringIdentity.identityOf( "/" ) ); - builder.prototype().api().set( entryPoints ); - return builder.newInstance(); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/ResourceBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/ResourceBuilder.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/ResourceBuilder.java deleted file mode 100644 index b3cb1b2..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/ResourceBuilder.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.resource; - -import java.io.IOException; -import java.util.Collections; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.identity.Identity; -import org.apache.polygene.api.injection.scope.Service; -import org.apache.polygene.api.injection.scope.Structure; -import org.apache.polygene.api.mixin.Mixins; -import org.apache.polygene.api.object.ObjectFactory; -import org.apache.polygene.api.value.ValueBuilder; -import org.apache.polygene.api.value.ValueBuilderFactory; -import org.apache.polygene.library.restlet.Command; -import org.apache.polygene.library.restlet.FormField; -import org.apache.polygene.library.restlet.RestForm; -import org.apache.polygene.library.restlet.RestLink; -import org.apache.polygene.library.restlet.crud.EntityRef; -import org.apache.polygene.library.restlet.identity.IdentityManager; -import org.apache.polygene.library.restlet.serialization.PolygeneConverter; -import org.restlet.data.Method; -import org.restlet.data.Reference; -import org.restlet.representation.Representation; -import org.restlet.representation.Variant; -import org.restlet.routing.Route; -import org.restlet.routing.Router; - -@Mixins( ResourceBuilder.Mixin.class ) -public interface ResourceBuilder -{ - EntityRef createEntityRef( Identity name, Reference base ); - - EntityRef createEntityRef( Identity name, RestLink get, RestLink put, RestLink delete ); - - RestLink createBaseLink( String name, Reference base, Method method, String description ); - - RestLink createLeafLink( String name, Reference base, Method method, String description ); - - Command createCommand( Reference base ); - - RestForm createNameForm( Reference base, String formName ); - - FormField createFormField( String name, String type ); - - <T extends HasIdentity> Representation toRepresentation( Class<T> type, T composite ); - - <T extends HasIdentity> T toObject( Class<T> type, Representation representation ) - throws IOException; - - Route findRoute( String name, Router router ); - - class Mixin - implements ResourceBuilder - { - @Service - private IdentityManager identityManager; - - private final PolygeneConverter converter; - - @Structure - private ValueBuilderFactory vbf; - - public Mixin( @Structure ObjectFactory objectFactory ) - { - converter = new PolygeneConverter( objectFactory ); - } - - @Override - public EntityRef createEntityRef( Identity identity, Reference base ) - { - String name = identityManager.extractName( identity ); - - RestLink get = createBaseLink( name, base, Method.GET, "Fetch " + name ); - RestLink put = createBaseLink( name, base, Method.PUT, "Save " + name ); - RestLink delete = createBaseLink( name, base, Method.DELETE, "Delete " + name ); - return createEntityRef( identity, get, put, delete ); - } - - @Override - public EntityRef createEntityRef( Identity identity, RestLink get, RestLink put, RestLink delete ) - { - ValueBuilder<EntityRef> refBuilder = vbf.newValueBuilder( EntityRef.class ); - EntityRef refPrototype = refBuilder.prototype(); - refPrototype.name().set( identityManager.extractName( identity ) ); - refPrototype.get().set( get ); - refPrototype.put().set( put ); - refPrototype.delete().set( delete ); - return refBuilder.newInstance(); - } - - @Override - public RestLink createBaseLink( String name, Reference base, Method method, String description ) - { - ValueBuilder<RestLink> builder = vbf.newValueBuilder( RestLink.class ); - RestLink prototype = builder.prototype(); - String path = base.toUri().resolve( name ).getPath(); - prototype.path().set( path.endsWith( "/" ) ? path : path + "/" ); - prototype.method().set( method.getName() ); - prototype.description().set( description ); - return builder.newInstance(); - } - - @Override - public RestLink createLeafLink( String name, Reference base, Method method, String description ) - { - ValueBuilder<RestLink> builder = vbf.newValueBuilder( RestLink.class ); - RestLink prototype = builder.prototype(); - String path = base.toUri().resolve( name ).getPath(); - prototype.path().set( path ); - prototype.method().set( method.getName() ); - prototype.description().set( description ); - return builder.newInstance(); - } - - public Command createCommand( Reference base ) - { - RestForm form = createNameForm( base, "create" ); - ValueBuilder<Command> builder = vbf.newValueBuilder( Command.class ); - builder.prototype().name().set( "create" ); - builder.prototype().form().set( form ); - return builder.newInstance(); - } - - public RestForm createNameForm( Reference base, String formName ) - { - ValueBuilder<RestForm> builder = vbf.newValueBuilder( RestForm.class ); - builder.prototype().link().set( createBaseLink( formName, base, Method.POST, "" ) ); - builder.prototype().fields().set( Collections.singletonList( createFormField( "name", FormField.TEXT ) ) ); - return builder.newInstance(); - } - - public FormField createFormField( String name, String type ) - { - ValueBuilder<FormField> builder = vbf.newValueBuilder( FormField.class ); - builder.prototype().name().set( name ); - builder.prototype().type().set( type ); - return builder.newInstance(); - } - - @Override - public <T extends HasIdentity> Representation toRepresentation( Class<T> type, T composite ) - { - return converter.toRepresentation( composite, new Variant(), null ); - } - - @Override - public <T extends HasIdentity> T toObject( Class<T> type, Representation representation ) - throws IOException - { - return converter.toObject( representation, type, null ); - } - - @Override - public Route findRoute( String name, Router router ) - { - return router.getRoutes().stream().filter( route -> name.equals( route.getName() ) ).findFirst().orElse( null ); - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/scripting/src/test/groovy/org/apache/polygene/library/scripting/HelloSpeakerTest.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/test/groovy/org/apache/polygene/library/scripting/HelloSpeakerTest.java b/libraries/scripting/src/test/groovy/org/apache/polygene/library/scripting/HelloSpeakerTest.java index 62c7ff6..9abcacf 100644 --- a/libraries/scripting/src/test/groovy/org/apache/polygene/library/scripting/HelloSpeakerTest.java +++ b/libraries/scripting/src/test/groovy/org/apache/polygene/library/scripting/HelloSpeakerTest.java @@ -23,10 +23,10 @@ import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.bootstrap.SingletonAssembler; import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; public class HelloSpeakerTest extends AbstractPolygeneTest { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptMixinTest.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptMixinTest.java b/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptMixinTest.java index ba12e68..8783da7 100644 --- a/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptMixinTest.java +++ b/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptMixinTest.java @@ -34,12 +34,12 @@ import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.LayerAssembly; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNull.notNullValue; -import static org.junit.Assert.assertThat; public class ScriptMixinTest extends AbstractPolygeneTest http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/servlet/src/test/java/org/apache/polygene/library/servlet/ServletTest.java ---------------------------------------------------------------------- diff --git a/libraries/servlet/src/test/java/org/apache/polygene/library/servlet/ServletTest.java b/libraries/servlet/src/test/java/org/apache/polygene/library/servlet/ServletTest.java index e16e24f..50c5ef7 100644 --- a/libraries/servlet/src/test/java/org/apache/polygene/library/servlet/ServletTest.java +++ b/libraries/servlet/src/test/java/org/apache/polygene/library/servlet/ServletTest.java @@ -35,8 +35,10 @@ import org.apache.polygene.library.servlet.lifecycle.AbstractPolygeneServletBoot import org.apache.polygene.test.util.FreePortFinder; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; public class ServletTest { @@ -45,11 +47,11 @@ public class ServletTest // START SNIPPET: bootstrap public static class FooServletContextListener - extends AbstractPolygeneServletBootstrap + extends AbstractPolygeneServletBootstrap { public ApplicationAssembly assemble( ApplicationAssemblyFactory applicationFactory ) - throws AssemblyException + throws AssemblyException { ApplicationAssembly appass = applicationFactory.newApplicationAssembly(); // END SNIPPET: bootstrap @@ -60,7 +62,6 @@ public class ServletTest // START SNIPPET: bootstrap return appass; } - } // END SNIPPET: bootstrap @@ -70,27 +71,27 @@ public class ServletTest // START SNIPPET: usage public static class FooServlet - extends PolygeneServlet + extends PolygeneServlet { @Override protected void doGet( HttpServletRequest req, HttpServletResponse resp ) - throws ServletException, IOException + throws ServletException, IOException { // Output the assembled Application's name as an example resp.getWriter().println( application().name() ); } - } // END SNIPPET: usage @Test public void test() - throws Exception + throws Exception { int port = FreePortFinder.findFreePortOnLoopback(); Server server = new Server( port ); - try { + try + { ServletContextHandler context = new ServletContextHandler(); context.setContextPath( "/" ); @@ -100,16 +101,16 @@ public class ServletTest server.setHandler( context ); server.start(); - try( CloseableHttpClient client = HttpClientBuilder.create().build() ) + try (CloseableHttpClient client = HttpClientBuilder.create().build()) { String result = client.execute( new HttpGet( "http://127.0.0.1:" + port + "/" ), new BasicResponseHandler() ); - Assert.assertEquals( APP_NAME, result.trim() ); + assertThat( result.trim(), equalTo( APP_NAME ) ); } - - } finally { + } + finally + { server.stop(); } } - } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/PasswordDomainTest.java ---------------------------------------------------------------------- diff --git a/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/PasswordDomainTest.java b/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/PasswordDomainTest.java index c2b3fb8..599447d 100644 --- a/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/PasswordDomainTest.java +++ b/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/PasswordDomainTest.java @@ -19,13 +19,6 @@ */ package org.apache.polygene.library.shiro; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.authc.UsernamePasswordToken; -import org.apache.shiro.authc.credential.PasswordService; -import org.apache.shiro.subject.Subject; -import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; -import org.junit.Test; import org.apache.polygene.api.common.Visibility; import org.apache.polygene.api.entity.EntityBuilder; import org.apache.polygene.api.injection.scope.Service; @@ -33,6 +26,7 @@ import org.apache.polygene.api.injection.scope.Structure; import org.apache.polygene.api.mixin.Mixins; import org.apache.polygene.api.unitofwork.UnitOfWork; import org.apache.polygene.api.unitofwork.UnitOfWorkCompletionException; +import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.index.rdf.assembly.RdfMemoryStoreAssembler; @@ -40,9 +34,17 @@ import org.apache.polygene.library.shiro.assembly.PasswordDomainAssembler; import org.apache.polygene.library.shiro.assembly.StandaloneShiroAssembler; import org.apache.polygene.library.shiro.domain.passwords.PasswordSecurable; import org.apache.polygene.library.shiro.ini.ShiroIniConfiguration; +import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.UsernamePasswordToken; +import org.apache.shiro.authc.credential.PasswordService; +import org.apache.shiro.subject.Subject; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNull.notNullValue; public class PasswordDomainTest extends AbstractPolygeneTest @@ -138,9 +140,9 @@ public class PasswordDomainTest currentUser.login( new UsernamePasswordToken( "foo", "bar" ) ); // END SNIPPET: usage - assertNotNull( "Unable to authenticate against PasswordRealmService", currentUser.getPrincipal() ); + assertThat( "Unable to authenticate against PasswordRealmService", currentUser.getPrincipal(), notNullValue() ); - assertFalse( currentUser.hasRole( "role-one" ) ); + assertThat( currentUser.hasRole( "role-one" ), is( false ) ); uow.discard(); } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/PermissionsDomainTest.java ---------------------------------------------------------------------- diff --git a/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/PermissionsDomainTest.java b/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/PermissionsDomainTest.java index 604b0bb..044fb87 100644 --- a/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/PermissionsDomainTest.java +++ b/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/PermissionsDomainTest.java @@ -19,14 +19,6 @@ */ package org.apache.polygene.library.shiro; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.authc.UsernamePasswordToken; -import org.apache.shiro.authc.credential.PasswordService; -import org.apache.shiro.subject.Subject; -import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; -import org.junit.Before; -import org.junit.Test; import org.apache.polygene.api.common.Visibility; import org.apache.polygene.api.entity.EntityBuilder; import org.apache.polygene.api.injection.scope.Service; @@ -34,6 +26,7 @@ import org.apache.polygene.api.injection.scope.Structure; import org.apache.polygene.api.mixin.Mixins; import org.apache.polygene.api.unitofwork.UnitOfWork; import org.apache.polygene.api.unitofwork.UnitOfWorkCompletionException; +import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.index.rdf.assembly.RdfMemoryStoreAssembler; @@ -45,11 +38,18 @@ import org.apache.polygene.library.shiro.domain.permissions.Role; import org.apache.polygene.library.shiro.domain.permissions.RoleAssignee; import org.apache.polygene.library.shiro.domain.permissions.RoleFactory; import org.apache.polygene.library.shiro.ini.ShiroIniConfiguration; +import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.UsernamePasswordToken; +import org.apache.shiro.authc.credential.PasswordService; +import org.apache.shiro.subject.Subject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; public class PermissionsDomainTest extends AbstractPolygeneTest @@ -123,7 +123,7 @@ public class PermissionsDomainTest private RoleFactory roleFactory; - @Before + @BeforeEach public void before_PermissionsDomainTest() { userFactory = serviceFinder.findService( UserFactory.class ).get(); http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/RealmServiceTest.java ---------------------------------------------------------------------- diff --git a/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/RealmServiceTest.java b/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/RealmServiceTest.java index 3a774a2..ff36fc0 100644 --- a/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/RealmServiceTest.java +++ b/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/RealmServiceTest.java @@ -19,16 +19,6 @@ */ package org.apache.polygene.library.shiro; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.authc.UsernamePasswordToken; -import org.apache.shiro.authc.credential.DefaultPasswordService; -import org.apache.shiro.authc.credential.PasswordMatcher; -import org.apache.shiro.authc.credential.PasswordService; -import org.apache.shiro.realm.Realm; -import org.apache.shiro.realm.SimpleAccountRealm; -import org.apache.shiro.subject.Subject; -import org.junit.Test; import org.apache.polygene.api.common.Visibility; import org.apache.polygene.api.mixin.Mixins; import org.apache.polygene.api.service.ServiceActivation; @@ -37,9 +27,20 @@ import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.library.shiro.assembly.StandaloneShiroAssembler; import org.apache.polygene.library.shiro.ini.ShiroIniConfiguration; +import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.UsernamePasswordToken; +import org.apache.shiro.authc.credential.DefaultPasswordService; +import org.apache.shiro.authc.credential.PasswordMatcher; +import org.apache.shiro.authc.credential.PasswordService; +import org.apache.shiro.realm.Realm; +import org.apache.shiro.realm.SimpleAccountRealm; +import org.apache.shiro.subject.Subject; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsNull.notNullValue; public class RealmServiceTest extends AbstractPolygeneTest @@ -113,7 +114,7 @@ public class RealmServiceTest Subject currentUser = SecurityUtils.getSubject(); UsernamePasswordToken token = new UsernamePasswordToken( "foo", "bar" ); currentUser.login( token ); - assertNotNull( "Unable to authenticate against MyRealmService", currentUser.getPrincipal() ); + assertThat( "Unable to authenticate against MyRealmService", currentUser.getPrincipal(), notNullValue() ); } } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/StandaloneShiroTest.java ---------------------------------------------------------------------- diff --git a/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/StandaloneShiroTest.java b/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/StandaloneShiroTest.java index 062077a..e959315 100644 --- a/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/StandaloneShiroTest.java +++ b/libraries/shiro-core/src/test/java/org/apache/polygene/library/shiro/StandaloneShiroTest.java @@ -19,7 +19,15 @@ */ package org.apache.polygene.library.shiro; +import org.apache.polygene.api.common.Visibility; +import org.apache.polygene.api.injection.scope.Service; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.library.shiro.assembly.StandaloneShiroAssembler; +import org.apache.polygene.library.shiro.ini.IniSecurityManagerService; +import org.apache.polygene.library.shiro.ini.ShiroIniConfiguration; import org.apache.polygene.test.AbstractPolygeneTest; +import org.apache.polygene.test.EntityTestAssembler; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.IncorrectCredentialsException; @@ -31,21 +39,14 @@ import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.session.Session; import org.apache.shiro.subject.Subject; import org.apache.shiro.util.ThreadContext; -import org.junit.Test; -import org.apache.polygene.api.common.Visibility; -import org.apache.polygene.api.injection.scope.Service; -import org.apache.polygene.bootstrap.AssemblyException; -import org.apache.polygene.bootstrap.ModuleAssembly; -import org.apache.polygene.library.shiro.assembly.StandaloneShiroAssembler; -import org.apache.polygene.library.shiro.ini.IniSecurityManagerService; -import org.apache.polygene.library.shiro.ini.ShiroIniConfiguration; -import org.apache.polygene.test.EntityTestAssembler; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.junit.jupiter.api.Assertions.fail; public class StandaloneShiroTest extends AbstractPolygeneTest @@ -114,7 +115,7 @@ public class StandaloneShiroTest Session session = currentUser.getSession(); session.setAttribute( "someKey", "aValue" ); String value = ( String ) session.getAttribute( "someKey" ); - assertEquals( "aValue", value ); + assertThat( value, equalTo( "aValue" ) ); LOG.info( "Retrieved the correct value! [" + value + "]" ); // let's login the current user so we can check against roles and permissions: @@ -139,7 +140,7 @@ public class StandaloneShiroTest //say who they are: //print their identifying principal (in this case, a username): - assertNotNull( currentUser.getPrincipal() ); + assertThat( currentUser.getPrincipal(), notNullValue() ); LOG.info( "User [" + currentUser.getPrincipal() + "] logged in successfully." ); //test a role: http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebHttpShiroTest.java ---------------------------------------------------------------------- diff --git a/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebHttpShiroTest.java b/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebHttpShiroTest.java index e34edd0..4acfe9e 100644 --- a/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebHttpShiroTest.java +++ b/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebHttpShiroTest.java @@ -19,8 +19,6 @@ */ package org.apache.polygene.library.shiro.web; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; import org.apache.polygene.api.common.Visibility; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; @@ -28,8 +26,10 @@ import org.apache.polygene.library.http.JettyConfiguration; import org.apache.polygene.library.http.JettyServiceAssembler; import org.apache.polygene.library.shiro.ini.ShiroIniConfiguration; import org.apache.polygene.library.shiro.web.assembly.HttpShiroAssembler; +import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; import org.apache.polygene.test.util.FreePortFinder; +import org.junit.jupiter.api.Test; public class WebHttpShiroTest extends AbstractPolygeneTest http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebRealmServiceTest.java ---------------------------------------------------------------------- diff --git a/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebRealmServiceTest.java b/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebRealmServiceTest.java index cebe368..b656104 100644 --- a/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebRealmServiceTest.java +++ b/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebRealmServiceTest.java @@ -43,13 +43,6 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.protocol.ExecutionContext; import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.apache.shiro.authc.credential.DefaultPasswordService; -import org.apache.shiro.authc.credential.PasswordMatcher; -import org.apache.shiro.authc.credential.PasswordService; -import org.apache.shiro.realm.Realm; -import org.apache.shiro.realm.SimpleAccountRealm; -import org.junit.Test; import org.apache.polygene.api.common.Visibility; import org.apache.polygene.api.mixin.Mixins; import org.apache.polygene.api.service.ServiceActivation; @@ -60,13 +53,20 @@ import org.apache.polygene.library.http.JettyConfiguration; import org.apache.polygene.library.http.JettyServiceAssembler; import org.apache.polygene.library.shiro.ini.ShiroIniConfiguration; import org.apache.polygene.library.shiro.web.assembly.HttpShiroAssembler; +import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; import org.apache.polygene.test.util.FreePortFinder; +import org.apache.shiro.authc.credential.DefaultPasswordService; +import org.apache.shiro.authc.credential.PasswordMatcher; +import org.apache.shiro.authc.credential.PasswordService; +import org.apache.shiro.realm.Realm; +import org.apache.shiro.realm.SimpleAccountRealm; +import org.junit.jupiter.api.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; import static org.apache.polygene.library.http.Servlets.addServlets; import static org.apache.polygene.library.http.Servlets.serve; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; public class WebRealmServiceTest extends AbstractPolygeneTest http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebServletShiroTest.java ---------------------------------------------------------------------- diff --git a/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebServletShiroTest.java b/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebServletShiroTest.java index 4d7dfe4..52733fc 100644 --- a/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebServletShiroTest.java +++ b/libraries/shiro-web/src/test/java/org/apache/polygene/library/shiro/web/WebServletShiroTest.java @@ -20,14 +20,17 @@ package org.apache.polygene.library.shiro.web; import java.util.EnumSet; +import org.apache.polygene.test.util.FreePortFinder; import org.apache.shiro.web.env.EnvironmentLoaderListener; import org.apache.shiro.web.servlet.ShiroFilter; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; -import org.junit.Test; -import org.apache.polygene.test.util.FreePortFinder; +import org.junit.jupiter.api.Test; -import static javax.servlet.DispatcherType.*; +import static javax.servlet.DispatcherType.ERROR; +import static javax.servlet.DispatcherType.FORWARD; +import static javax.servlet.DispatcherType.INCLUDE; +import static javax.servlet.DispatcherType.REQUEST; public class WebServletShiroTest { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/libraries/spring/build.gradle ---------------------------------------------------------------------- diff --git a/libraries/spring/build.gradle b/libraries/spring/build.gradle index 26a9dde..ca39df9 100644 --- a/libraries/spring/build.gradle +++ b/libraries/spring/build.gradle @@ -33,5 +33,6 @@ dependencies { testImplementation polygene.core.testsupport testImplementation libraries.spring_testsupport + testImplementation libraries.junit_vintage testRuntimeOnly libraries.logback }