Skip to content

Commit

Permalink
KEYCLOAK-2474 Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
mposolda committed Jun 21, 2016
1 parent c4513fd commit da945a6
Show file tree
Hide file tree
Showing 24 changed files with 936 additions and 11 deletions.
Expand Up @@ -36,7 +36,7 @@ public List<CompanyRepresentation> getCompanies() {
@Path("") @Path("")
@NoCache @NoCache
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Response createProviderInstance(CompanyRepresentation rep) { public Response createCompany(CompanyRepresentation rep) {
session.getProvider(ExampleService.class).addCompany(rep); session.getProvider(ExampleService.class).addCompany(rep);
return Response.created(session.getContext().getUri().getAbsolutePathBuilder().path(rep.getId()).build()).build(); return Response.created(session.getContext().getUri().getAbsolutePathBuilder().path(rep.getId()).build()).build();
} }
Expand Down
Expand Up @@ -20,14 +20,6 @@
columnNames="ID" columnNames="ID"
/> />


<addForeignKeyConstraint
constraintName="FK_COMPANY_REALM"
baseTableName="EXAMPLE_COMPANY"
baseColumnNames="REALM_ID"
referencedTableName="REALM"
referencedColumnNames="ID"
/>

</changeSet> </changeSet>


</databaseChangeLog> </databaseChangeLog>
@@ -0,0 +1,51 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed 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.keycloak.testsuite.domainextension;


import org.keycloak.testsuite.domainextension.jpa.Company;

public class CompanyRepresentation {

private String id;
private String name;

public CompanyRepresentation() {
}

public CompanyRepresentation(Company company) {
id = company.getId();
name = company.getName();
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public void setId(String id) {
this.id = id;
}

public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,66 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed 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.keycloak.testsuite.domainextension.jpa;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name = "EXAMPLE_COMPANY")
@NamedQueries({ @NamedQuery(name = "findByRealm", query = "from Company where realmId = :realmId") })
public class Company {

@Id
@Column(name = "ID")
private String id;

@Column(name = "NAME", nullable = false)
private String name;

@Column(name = "REALM_ID", nullable = false)
private String realmId;

public String getId() {
return id;
}

public String getRealmId() {
return realmId;
}

public String getName() {
return name;
}

public void setId(String id) {
this.id = id;
}

public void setName(String name) {
this.name = name;
}

public void setRealmId(String realmId) {
this.realmId = realmId;
}
}
@@ -0,0 +1,50 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed 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.keycloak.testsuite.domainextension.jpa;

import java.util.Collections;
import java.util.List;

import org.keycloak.connections.jpa.entityprovider.JpaEntityProvider;

/**
* @author <a href="mailto:erik.mulder@docdatapayments.com">Erik Mulder</a>
*
* Example JpaEntityProvider.
*/
public class ExampleJpaEntityProvider implements JpaEntityProvider {

@Override
public List<Class<?>> getEntities() {
return Collections.<Class<?>>singletonList(Company.class);
}

@Override
public String getChangelogLocation() {
return "META-INF/example-changelog.xml";
}

@Override
public void close() {
}

@Override
public String getFactoryId() {
return ExampleJpaEntityProviderFactory.ID;
}
}
@@ -0,0 +1,57 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed 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.keycloak.testsuite.domainextension.jpa;

import org.keycloak.Config.Scope;
import org.keycloak.connections.jpa.entityprovider.JpaEntityProvider;
import org.keycloak.connections.jpa.entityprovider.JpaEntityProviderFactory;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;

/**
* @author <a href="mailto:erik.mulder@docdatapayments.com">Erik Mulder</a>
*
* Example JpaEntityProviderFactory.
*/
public class ExampleJpaEntityProviderFactory implements JpaEntityProviderFactory {

protected static final String ID = "example-entity-provider";

@Override
public JpaEntityProvider create(KeycloakSession session) {
return new ExampleJpaEntityProvider();
}

@Override
public String getId() {
return ID;
}

@Override
public void init(Scope config) {
}

@Override
public void postInit(KeycloakSessionFactory factory) {
}

@Override
public void close() {
}

}
@@ -0,0 +1,77 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed 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.keycloak.testsuite.domainextension.rest;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.jboss.resteasy.annotations.cache.NoCache;
import org.keycloak.models.KeycloakSession;
import org.keycloak.testsuite.domainextension.CompanyRepresentation;
import org.keycloak.testsuite.domainextension.spi.ExampleService;

public class CompanyResource {

private final KeycloakSession session;

public CompanyResource(KeycloakSession session) {
this.session = session;
}

@GET
@Path("")
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public List<CompanyRepresentation> getCompanies() {
return session.getProvider(ExampleService.class).listCompanies();
}

@DELETE
@Path("")
@NoCache
public void deleteAllCompanies() {
session.getProvider(ExampleService.class).deleteAllCompanies();
}

@POST
@Path("")
@NoCache
@Consumes(MediaType.APPLICATION_JSON)
public Response createCompany(CompanyRepresentation rep) {
session.getProvider(ExampleService.class).addCompany(rep);
return Response.created(session.getContext().getUri().getAbsolutePathBuilder().path(rep.getId()).build()).build();
}

@GET
@NoCache
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public CompanyRepresentation getCompany(@PathParam("id") final String id) {
return session.getProvider(ExampleService.class).findCompany(id);
}

}
@@ -0,0 +1,40 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed 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.keycloak.testsuite.domainextension.rest;

import org.keycloak.models.KeycloakSession;
import org.keycloak.services.resource.RealmResourceProvider;

public class ExampleRealmResourceProvider implements RealmResourceProvider {

private KeycloakSession session;

public ExampleRealmResourceProvider(KeycloakSession session) {
this.session = session;
}

@Override
public Object getResource() {
return new ExampleRestResource(session);
}

@Override
public void close() {
}

}

0 comments on commit da945a6

Please sign in to comment.