├── .editorconfig ├── .gitignore ├── .travis.yml ├── README.md ├── app-template.yaml ├── configuration ├── application-roles.properties ├── application-users.properties └── cicd-settings-nexus3.xml ├── pipeline-bc.yaml ├── pom.xml └── src ├── main ├── java │ ├── com │ │ └── openshift │ │ │ ├── helpers │ │ │ └── Load.java │ │ │ └── service │ │ │ └── DemoResource.java │ └── org │ │ └── jboss │ │ └── as │ │ └── quickstarts │ │ └── tasksrs │ │ ├── model │ │ ├── Resources.java │ │ ├── Task.java │ │ ├── TaskDao.java │ │ ├── TaskDaoImpl.java │ │ ├── User.java │ │ ├── UserDao.java │ │ └── UserDaoImpl.java │ │ └── service │ │ ├── TaskResource.java │ │ └── UserResource.java ├── resources │ └── META-INF │ │ └── persistence.xml └── webapp │ ├── WEB-INF │ ├── beans.xml │ ├── tasks-rs-ds.xml │ └── web.xml │ ├── css │ ├── patternfly-additions.css │ ├── patternfly-additions.css.map │ ├── patternfly-additions.min.css │ ├── patternfly-additions.min.css.map │ ├── patternfly.css │ ├── patternfly.css.map │ ├── patternfly.min.css │ ├── patternfly.min.css.map │ ├── styles-additions.css │ ├── styles-additions.min.css │ ├── styles.css │ └── styles.min.css │ ├── fonts │ ├── FontAwesome.otf │ ├── OpenSans-Bold-webfont.eot │ ├── OpenSans-Bold-webfont.svg │ ├── OpenSans-Bold-webfont.ttf │ ├── OpenSans-Bold-webfont.woff │ ├── OpenSans-BoldItalic-webfont.eot │ ├── OpenSans-BoldItalic-webfont.svg │ ├── OpenSans-BoldItalic-webfont.ttf │ ├── OpenSans-BoldItalic-webfont.woff │ ├── OpenSans-ExtraBold-webfont.eot │ ├── OpenSans-ExtraBold-webfont.svg │ ├── OpenSans-ExtraBold-webfont.ttf │ ├── OpenSans-ExtraBold-webfont.woff │ ├── OpenSans-ExtraBoldItalic-webfont.eot │ ├── OpenSans-ExtraBoldItalic-webfont.svg │ ├── OpenSans-ExtraBoldItalic-webfont.ttf │ ├── OpenSans-ExtraBoldItalic-webfont.woff │ ├── OpenSans-Italic-webfont.eot │ ├── OpenSans-Italic-webfont.svg │ ├── OpenSans-Italic-webfont.ttf │ ├── OpenSans-Italic-webfont.woff │ ├── OpenSans-Light-webfont.eot │ ├── OpenSans-Light-webfont.svg │ ├── OpenSans-Light-webfont.ttf │ ├── OpenSans-Light-webfont.woff │ ├── OpenSans-LightItalic-webfont.eot │ ├── OpenSans-LightItalic-webfont.svg │ ├── OpenSans-LightItalic-webfont.ttf │ ├── OpenSans-LightItalic-webfont.woff │ ├── OpenSans-Regular-webfont.eot │ ├── OpenSans-Regular-webfont.svg │ ├── OpenSans-Regular-webfont.ttf │ ├── OpenSans-Regular-webfont.woff │ ├── OpenSans-Semibold-webfont.eot │ ├── OpenSans-Semibold-webfont.svg │ ├── OpenSans-Semibold-webfont.ttf │ ├── OpenSans-Semibold-webfont.woff │ ├── OpenSans-SemiboldItalic-webfont.eot │ ├── OpenSans-SemiboldItalic-webfont.svg │ ├── OpenSans-SemiboldItalic-webfont.ttf │ ├── OpenSans-SemiboldItalic-webfont.woff │ ├── PatternFlyIcons-webfont.eot │ ├── PatternFlyIcons-webfont.svg │ ├── PatternFlyIcons-webfont.ttf │ ├── PatternFlyIcons-webfont.woff │ ├── fontawesome-webfont.eot │ ├── fontawesome-webfont.svg │ ├── fontawesome-webfont.ttf │ ├── fontawesome-webfont.woff │ ├── fontawesome-webfont.woff2 │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 │ ├── img │ ├── OpenShift-Logo-NoText.svg │ ├── OpenShift-Logo-Text.svg │ ├── OpenShift-logo.svg │ ├── RH_Atomic-Logo-NoText.svg │ ├── RH_Atomic-Logo-Text.svg │ ├── RH_atomic.svg │ ├── apple-touch-icon-precomposed-114.png │ ├── apple-touch-icon-precomposed-144.png │ ├── apple-touch-icon-precomposed-152.png │ ├── apple-touch-icon-precomposed-180.png │ ├── apple-touch-icon-precomposed-57.png │ ├── apple-touch-icon-precomposed-72.png │ ├── apple-touch-icon-precomposed-76.png │ ├── bg-login.jpg │ ├── bg-navbar-pf-alt.svg │ ├── brand-alt.svg │ ├── brand.svg │ ├── favicon.ico │ ├── kubernetes-Logo.svg │ ├── kubernetes.svg │ ├── logo-alt.svg │ ├── logo.svg │ ├── spinner-inverse-lg.gif │ ├── spinner-inverse-sm.gif │ ├── spinner-inverse-xs.gif │ ├── spinner-inverse.gif │ ├── spinner-lg.gif │ ├── spinner-sm.gif │ ├── spinner-xs.gif │ └── spinner.gif │ ├── index.jsp │ └── js │ ├── demo.js │ ├── patternfly.js │ └── patternfly.min.js ├── site └── site.xml └── test ├── java └── org │ └── jboss │ └── as │ └── quickstarts │ └── tasksrs │ ├── DefaultDeployment.java │ ├── TaskDaoTest.java │ ├── UserDaoTest.java │ ├── category │ ├── IntegrationTest.java │ └── UnitTest.java │ └── service │ ├── TaskResourceTest.java │ └── UserResourceTest.java └── resources ├── META-INF └── test-persistence.xml ├── arquillian.xml ├── import.sql └── test-ds.xml /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 4 7 | trim_trailing_whitespace = true 8 | end_of_line = lf 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | target/ 3 | logs/ 4 | .classpath 5 | .settings 6 | .project 7 | 8 | # Mobile Tools for Java (J2ME) 9 | .mtj.tmp/ 10 | 11 | # Package Files # 12 | *.jar 13 | *.war 14 | *.ear 15 | 16 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 17 | hs_err_pid* 18 | 19 | # Used in openshift profile 20 | /deployments/ 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | env: 2 | global: 3 | - IMAGE_REPO=quay.io/siamaksade/tasks-sample-app 4 | 5 | cache: 6 | directories: 7 | - $HOME/.m2 8 | 9 | services: 10 | - docker 11 | 12 | language: java 13 | 14 | jdk: 15 | - oraclejdk8 16 | 17 | before_install: 18 | - docker login -u $QUAY_USER -p $QUAY_PASS quay.io 19 | - curl -sL -o $HOME/s2i.tar.gz https://github.com/openshift/source-to-image/releases/download/v1.1.10/source-to-image-v1.1.10-27f0729d-linux-amd64.tar.gz 20 | - pushd $HOME/bin && tar xvfz $HOME/s2i.tar.gz && popd 21 | 22 | script: 23 | - mvn package 24 | - ${HOME}/bin/s2i build . openshift/wildfly-120-centos7 $IMAGE_REPO:$TRAVIS_BRANCH-release 25 | - docker push $IMAGE_REPO:$TRAVIS_BRANCH-release 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | REST-based Tasks Sample App for OpenShift 2 | ============================== 3 | [![Build Status](https://travis-ci.org/OpenShiftDemos/openshift-tasks.svg?branch=eap-7)](https://travis-ci.org/OpenShiftDemos/openshift-tasks) 4 | [![Docker Repository on Quay](https://quay.io/repository/siamaksade/tasks-sample-app/status "Docker Repository on Quay")](https://quay.io/repository/siamaksade/tasks-sample-app) 5 | 6 | What is it? 7 | ----------- 8 | a 9 | The `tasks-rs` quickstart demonstrates how to implement a JAX-RS service that uses JPA 2.0 persistence deployed to Red Hat JBoss Enterprise Application Platform. 10 | 11 | The application manages User and Task JPA entities. A user represents an authenticated principal and is associated with zero or more Tasks. Service methods validate that there is an authenticated principal and the first time a principal is seen, a JPA User entity is created to correspond to the principal. JAX-RS annotated methods are provided for associating Tasks with this User and for listing and removing Tasks. 12 | 13 | _Note_: This quickstart uses the H2 database included with Red Hat JBoss Enterprise Application Platform 6. It is a lightweight, relational example datasource that is used for examples only. It is not robust or scalable, is not supported, and should NOT be used in a production environment!_ 14 | 15 | _Note_: This quickstart uses a `*-ds.xml` datasource configuration file for convenience and ease of database configuration. These files are deprecated in JBoss EAP 6.4 and should not be used in a production environment. Instead, you should configure the datasource using the Management CLI or Management Console. Datasource configuration is documented in the [Administration and Configuration Guide](https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/) for Red Hat JBoss Enterprise Application Platform._ 16 | 17 | 18 | REST Endpoints on OpenShift 19 | ------------------- 20 | 21 | * Create task 22 | 23 | ``` 24 | curl -i -u 'redhat:redhat1!' -H "Content-Length: 0" -X POST http://tasks-dev.10.1.2.10.xip.io/ws/tasks/task1 25 | ``` 26 | 27 | * Get a task by id 28 | 29 | ``` 30 | curl -u 'redhat:redhat1!' -H "Accept: application/json" -X GET http://tasks-dev.10.1.2.10.xip.io/ws/tasks/1 31 | ``` 32 | 33 | * Get all user tasks 34 | 35 | ``` 36 | 37 | curl -u 'redhat:redhat1!' -H "Accept: application/json" -X GET http://tasks-dev.10.1.2.10.xip.io/ws/tasks 38 | ``` 39 | 40 | * Delete a task by id 41 | 42 | ``` 43 | curl -i -u 'redhat:redhat1!' -X DELETE http://tasks-dev.10.1.2.10.xip.io/ws/tasks/1 44 | ``` 45 | 46 | * Generate CPU load. Last parameter is duration of load in seconds 47 | 48 | ``` 49 | curl -X GET http://tasks-dev.10.1.2.10.xip.io/demo/load/5 # 5 seconds 50 | ``` 51 | -------------------------------------------------------------------------------- /app-template.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Template 3 | labels: 4 | template: openshift-tasks 5 | metadata: 6 | name: openshift-tasks 7 | objects: 8 | - apiVersion: v1 9 | kind: ImageStream 10 | metadata: 11 | labels: 12 | application: ${APPLICATION_NAME} 13 | name: ${APPLICATION_NAME} 14 | - apiVersion: v1 15 | kind: Service 16 | metadata: 17 | annotations: 18 | description: The web server's http port. 19 | labels: 20 | application: ${APPLICATION_NAME} 21 | name: ${APPLICATION_NAME} 22 | spec: 23 | ports: 24 | - port: 8080 25 | targetPort: 8080 26 | selector: 27 | deploymentConfig: ${APPLICATION_NAME} 28 | - apiVersion: v1 29 | id: ${APPLICATION_NAME}-http 30 | kind: Route 31 | metadata: 32 | annotations: 33 | description: Route for application's http service. 34 | labels: 35 | application: ${APPLICATION_NAME} 36 | name: ${APPLICATION_NAME} 37 | spec: 38 | to: 39 | name: ${APPLICATION_NAME} 40 | - apiVersion: v1 41 | kind: BuildConfig 42 | metadata: 43 | labels: 44 | application: ${APPLICATION_NAME} 45 | name: ${APPLICATION_NAME} 46 | spec: 47 | output: 48 | to: 49 | kind: ImageStreamTag 50 | name: ${APPLICATION_NAME}:latest 51 | source: 52 | git: 53 | ref: ${SOURCE_REF} 54 | uri: ${SOURCE_URL} 55 | type: Git 56 | strategy: 57 | sourceStrategy: 58 | forcePull: true 59 | from: 60 | kind: ImageStreamTag 61 | name: jboss-eap64-openshift:latest 62 | namespace: openshift 63 | type: Source 64 | triggers: 65 | - github: 66 | secret: kJZLvfQr3hZg 67 | type: GitHub 68 | - generic: 69 | secret: kJZLvfQr3hZg 70 | type: Generic 71 | - imageChange: {} 72 | type: ImageChange 73 | - type: ConfigChange 74 | - apiVersion: v1 75 | kind: DeploymentConfig 76 | metadata: 77 | labels: 78 | application: ${APPLICATION_NAME} 79 | name: ${APPLICATION_NAME} 80 | spec: 81 | replicas: 1 82 | selector: 83 | deploymentConfig: ${APPLICATION_NAME} 84 | strategy: 85 | resources: {} 86 | rollingParams: 87 | intervalSeconds: 1 88 | maxSurge: 25% 89 | maxUnavailable: 25% 90 | timeoutSeconds: 600 91 | updatePeriodSeconds: 1 92 | type: Rolling 93 | template: 94 | metadata: 95 | labels: 96 | application: ${APPLICATION_NAME} 97 | deploymentConfig: ${APPLICATION_NAME} 98 | name: ${APPLICATION_NAME} 99 | spec: 100 | containers: 101 | - env: 102 | - name: MY_POD_IP 103 | valueFrom: 104 | fieldRef: 105 | apiVersion: v1 106 | fieldPath: status.podIP 107 | - name: OPENSHIFT_KUBE_PING_LABELS 108 | value: application=${APPLICATION_NAME} 109 | - name: OPENSHIFT_KUBE_PING_NAMESPACE 110 | valueFrom: 111 | fieldRef: 112 | fieldPath: metadata.namespace 113 | - name: HORNETQ_CLUSTER_PASSWORD 114 | value: kJZLvfQr3hZg 115 | - name: JGROUPS_CLUSTER_PASSWORD 116 | value: kJZLvfQr3hZg 117 | image: ${APPLICATION_NAME} 118 | imagePullPolicy: Always 119 | livenessProbe: 120 | failureThreshold: 3 121 | httpGet: 122 | path: /ws/demo/healthcheck 123 | port: 8080 124 | scheme: HTTP 125 | initialDelaySeconds: 45 126 | periodSeconds: 45 127 | successThreshold: 1 128 | timeoutSeconds: 1 129 | name: ${APPLICATION_NAME} 130 | ports: 131 | - containerPort: 8778 132 | name: jolokia 133 | protocol: TCP 134 | - containerPort: 8080 135 | name: http 136 | protocol: TCP 137 | - containerPort: 8888 138 | name: ping 139 | protocol: TCP 140 | readinessProbe: 141 | failureThreshold: 3 142 | httpGet: 143 | path: /ws/demo/healthcheck 144 | port: 8080 145 | scheme: HTTP 146 | initialDelaySeconds: 20 147 | periodSeconds: 5 148 | successThreshold: 1 149 | timeoutSeconds: 1 150 | terminationGracePeriodSeconds: 60 151 | triggers: 152 | - imageChangeParams: 153 | automatic: true 154 | containerNames: 155 | - ${APPLICATION_NAME} 156 | from: 157 | kind: ImageStream 158 | name: ${APPLICATION_NAME} 159 | type: ImageChange 160 | - type: ConfigChange 161 | parameters: 162 | - description: The name for the application. 163 | name: APPLICATION_NAME 164 | required: true 165 | value: tasks 166 | - description: Git source URI for application 167 | name: SOURCE_URL 168 | required: true 169 | value: https://github.com/openshiftdemos/openshift-tasks 170 | - description: Git branch/tag reference 171 | name: SOURCE_REF 172 | value: master 173 | -------------------------------------------------------------------------------- /configuration/application-roles.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Properties declaration of users roles for the realm 'ApplicationRealm' which is the default realm 3 | # for application services on a new installation. 4 | # 5 | # This includes the following protocols: remote ejb, remote jndi, web, remote jms 6 | # 7 | # Users can be added to this properties file at any time, updates after the server has started 8 | # will be automatically detected. 9 | # 10 | # The format of this file is as follows: - 11 | # username=role1,role2,role3 12 | # 13 | # A utility script is provided which can be executed from the bin folder to add the users: - 14 | # - Linux 15 | # bin/add-user.sh 16 | # 17 | # - Windows 18 | # bin\add-user.bat 19 | # 20 | # The following illustrates how an admin user could be defined. 21 | # 22 | #admin=PowerUser,BillingAdmin, 23 | #guest=guest 24 | redhat=guest 25 | -------------------------------------------------------------------------------- /configuration/application-users.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Properties declaration of users for the realm 'ApplicationRealm' which is the default realm 3 | # for application services on a new installation. 4 | # 5 | # This includes the following protocols: remote ejb, remote jndi, web, remote jms 6 | # 7 | # Users can be added to this properties file at any time, updates after the server has started 8 | # will be automatically detected. 9 | # 10 | # The format of this realm is as follows: - 11 | # username=HEX( MD5( username ':' realm ':' password)) 12 | # 13 | # A utility script is provided which can be executed from the bin folder to add the users: - 14 | # - Linux 15 | # bin/add-user.sh 16 | # 17 | # - Windows 18 | # bin\add-user.bat 19 | # 20 | #$REALM_NAME=ApplicationRealm$ This line is used by the add-user utility to identify the realm name already used in this file. 21 | # 22 | # The following illustrates how an admin user could be defined, this 23 | # is for illustration only and does not correspond to a usable password. 24 | # 25 | #admin=2a0923285184943425d1f53ddd58ec7a 26 | redhat=a61461431d8a3a52ea041ea5d25dcbc2 27 | -------------------------------------------------------------------------------- /configuration/cicd-settings-nexus3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | nexus 5 | deployment 6 | deployment123 7 | 8 | 9 | 10 | 11 | 12 | nexus 13 | * 14 | http://nexus:8081/repository/maven-all-public/ 15 | 16 | 17 | 18 | 19 | nexus 20 | 21 | 22 | 23 | 24 | central 25 | http://central 26 | true 27 | true 28 | 29 | 30 | 31 | 32 | central 33 | http://central 34 | true 35 | true 36 | 37 | 38 | 39 | 40 | 41 | 42 | nexus 43 | 44 | 45 | -------------------------------------------------------------------------------- /pipeline-bc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: BuildConfig 3 | metadata: 4 | annotations: 5 | pipeline.alpha.openshift.io/uses: '[{"name": "tasks", "namespace": "", "kind": "DeploymentConfig"}]' 6 | labels: 7 | name: tasks-pipeline 8 | name: tasks-pipeline 9 | spec: 10 | strategy: 11 | jenkinsPipelineStrategy: 12 | jenkinsfile: |- 13 | node('maven') { 14 | stage 'build' 15 | openshiftBuild(buildConfig: 'tasks', showBuildLogs: 'true') 16 | 17 | stage 'deploy' 18 | openshiftDeploy(deploymentConfig: 'tasks') 19 | } 20 | type: JenkinsPipeline 21 | triggers: 22 | - github: 23 | secret: CzgPZAZ5m2 24 | type: GitHub 25 | - generic: 26 | secret: CzgPZAZ5m2 27 | type: Generic 28 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | org.jboss.quickstarts.eap 22 | jboss-tasks-rs 23 | 6.4.0-SNAPSHOT 24 | war 25 | JBoss EAP - Tasks JAX-RS App 26 | 27 | 28 | Apache License, Version 2.0 29 | repo 30 | http://www.apache.org/licenses/LICENSE-2.0.html 31 | 32 | 33 | 34 | 35 | 36 | 38 | UTF-8 39 | 40 | 41 | 7.4.Final 42 | 43 | 44 | 6.4.0.GA 45 | 46 | 47 | 2.19.1 48 | 2.1.1 49 | 50 | 51 | 1.8 52 | 1.8 53 | 54 | 55 | 56 | 57 | openshift-repository 58 | https://mirror.openshift.com/nexus/content/groups/public 59 | 60 | 61 | 62 | 63 | 64 | nexus 65 | http://nexus:8081/content/repositories/releases 66 | 67 | 68 | nexus 69 | http://nexus:8081/content/repositories/snapshots 70 | 71 | 72 | 73 | 74 | 75 | 76 | org.jboss.bom.eap 77 | jboss-javaee-6.0-with-tools 78 | ${version.jboss.bom.eap} 79 | pom 80 | import 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | javax.enterprise 89 | cdi-api 90 | provided 91 | 92 | 93 | 94 | 95 | org.hibernate.javax.persistence 96 | hibernate-jpa-2.0-api 97 | provided 98 | 99 | 100 | 101 | 102 | org.jboss.spec.javax.ws.rs 103 | jboss-jaxrs-api_1.1_spec 104 | provided 105 | 106 | 107 | org.jboss.resteasy 108 | resteasy-jackson-provider 109 | 2.3.1.GA 110 | provided 111 | 112 | 113 | 114 | 115 | org.jboss.spec.javax.ejb 116 | jboss-ejb-api_3.1_spec 117 | provided 118 | 119 | 120 | 121 | 122 | junit 123 | junit 124 | test 125 | 126 | 127 | 128 | org.jboss.arquillian.junit 129 | arquillian-junit-container 130 | test 131 | 132 | 133 | 134 | org.jboss.arquillian.protocol 135 | arquillian-protocol-servlet 136 | test 137 | 138 | 139 | 140 | org.mockito 141 | mockito-core 142 | 2.0.54-beta 143 | test 144 | 145 | 146 | 147 | com.sun.jersey 148 | jersey-client 149 | 1.12 150 | test 151 | 152 | 153 | 154 | 155 | 157 | openshift-tasks 158 | 159 | 160 | org.apache.maven.plugins 161 | maven-compiler-plugin 162 | 3.8.0 163 | 164 | ${maven.compiler.source} 165 | ${maven.compiler.target} 166 | UTF-8 167 | 168 | 169 | 170 | maven-war-plugin 171 | ${version.war.plugin} 172 | 173 | 174 | false 175 | 176 | 177 | 179 | 180 | maven-surefire-plugin 181 | ${version.surefire.plugin} 182 | 183 | 184 | 185 | 186 | org.jboss.as.plugins 187 | jboss-as-maven-plugin 188 | ${version.jboss.maven.plugin} 189 | 190 | 191 | org.sonarsource.scanner.maven 192 | sonar-maven-plugin 193 | 3.3.0.603 194 | 195 | 196 | org.jacoco 197 | jacoco-maven-plugin 198 | 0.7.9 199 | 200 | 201 | default-prepare-agent 202 | 203 | prepare-agent 204 | 205 | 206 | 207 | default-report 208 | prepare-package 209 | 210 | report 211 | 212 | 213 | 214 | 215 | 216 | org.ec4j.maven 217 | editorconfig-maven-plugin 218 | 0.0.5 219 | 220 | 221 | check 222 | verify 223 | 224 | check 225 | 226 | 227 | 228 | 229 | 230 | deployments/** 231 | src/main/webapp/css/* 232 | src/main/webapp/fonts/* 233 | src/main/webapp/img/* 234 | src/main/webapp/js/* 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | org.apache.maven.plugins 245 | maven-javadoc-plugin 246 | 2.9 247 | 248 | 249 | 250 | javadoc 251 | 252 | 253 | 254 | 255 | 256 | org.apache.maven.plugins 257 | maven-pmd-plugin 258 | 3.8 259 | 260 | 261 | org.owasp 262 | dependency-check-maven 263 | 2.1.1 264 | 265 | true 266 | true 267 | 268 | 269 | 270 | 271 | aggregate 272 | 273 | 274 | 275 | 276 | 277 | org.jacoco 278 | jacoco-maven-plugin 279 | 0.7.9 280 | 281 | 282 | 283 | report 284 | 285 | 286 | 287 | 288 | 289 | org.apache.maven.plugins 290 | maven-checkstyle-plugin 291 | 2.17 292 | 293 | 294 | 295 | checkstyle 296 | 297 | 298 | 299 | 300 | 301 | org.codehaus.mojo 302 | findbugs-maven-plugin 303 | 3.0.5 304 | 305 | 306 | org.apache.maven.plugins 307 | maven-surefire-report-plugin 308 | 2.20.1 309 | 310 | 311 | org.apache.maven.plugins 312 | maven-project-info-reports-plugin 313 | 2.6 314 | 315 | 316 | 317 | summary 318 | dependency-management 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 330 | 332 | default 333 | 334 | true 335 | 336 | 337 | 338 | 339 | maven-surefire-plugin 340 | 341 | org.jboss.as.quickstarts.tasksrs.category.UnitTest 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | int-tests 350 | 351 | 352 | 353 | maven-surefire-plugin 354 | 355 | org.jboss.as.quickstarts.tasksrs.category.IntegrationTest 356 | 357 | 358 | 359 | 360 | 361 | 362 | 364 | 366 | 367 | arq-jbossas-managed 368 | 369 | 370 | org.jboss.as 371 | jboss-as-arquillian-container-managed 372 | test 373 | 374 | 375 | 376 | 377 | 378 | 380 | 381 | arq-jbossas-remote 382 | 383 | 384 | org.jboss.as 385 | jboss-as-arquillian-container-remote 386 | test 387 | 388 | 389 | 390 | 391 | 393 | 395 | 397 | 398 | openshift 399 | 400 | 401 | 402 | maven-surefire-plugin 403 | 404 | true 405 | 406 | 407 | 408 | maven-war-plugin 409 | 2.4 410 | 411 | false 412 | deployments 413 | ROOT 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/helpers/Load.java: -------------------------------------------------------------------------------- 1 | package com.openshift.helpers; 2 | 3 | public class Load { 4 | public void generateLoad(long duration) { 5 | int numCore = 2; 6 | int numThreadsPerCore = 2; 7 | double load = 0.8; 8 | for (int thread = 0; thread < numCore * numThreadsPerCore; thread++) { 9 | new BusyThread("Thread" + thread, load, duration).start(); 10 | } 11 | } 12 | 13 | private class BusyThread extends Thread { 14 | private double load; 15 | private long duration; 16 | 17 | public BusyThread(String name, double load, long duration) { 18 | super(name); 19 | this.load = load; 20 | this.duration = duration; 21 | } 22 | 23 | 24 | @Override 25 | public void run() { 26 | long startTime = System.currentTimeMillis(); 27 | try { 28 | // Loop for the given duration 29 | while (System.currentTimeMillis() - startTime < duration) { 30 | if (System.currentTimeMillis() % 100 == 0) { 31 | Thread.sleep((long) Math.floor((1 - load) * 100)); 32 | } 33 | } 34 | } catch (InterruptedException e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/service/DemoResource.java: -------------------------------------------------------------------------------- 1 | package com.openshift.service; 2 | 3 | import com.openshift.helpers.Load; 4 | 5 | 6 | import javax.ws.rs.GET; 7 | import javax.ws.rs.Path; 8 | import javax.ws.rs.PathParam; 9 | import javax.ws.rs.Produces; 10 | import javax.ws.rs.core.Response; 11 | import javax.ws.rs.core.Context; 12 | import javax.ws.rs.core.SecurityContext; 13 | import java.io.IOException; 14 | import java.util.logging.Level; 15 | import java.util.logging.Logger; 16 | 17 | /** 18 | * A JAX-RS resource for exposing REST endpoints for Task manipulation 19 | */ 20 | @Path("demo") 21 | public class DemoResource { 22 | 23 | // application instance health 24 | // 1 is healthy 25 | private static Integer health = 1; 26 | 27 | @GET 28 | @Path("load/{seconds}") 29 | @Produces({"application/json"}) 30 | public String generateLoad(@Context SecurityContext context, @PathParam("seconds") int seconds) { 31 | Load cpuLoad = new Load(); 32 | cpuLoad.generateLoad(seconds * 1000); 33 | String response = new String("Load being generated for " + seconds + " seconds."); 34 | Logger log = Logger.getLogger(DemoResource.class.getName()); 35 | log.log(Level.INFO, "INFO: Requested to generate load for " + seconds + " seconds."); 36 | return "{\"response\":\"" + response + "\"}"; 37 | } 38 | 39 | @GET 40 | @Path("log/info") 41 | @Produces({"application/json"}) 42 | public String logInfo(@Context SecurityContext context) { 43 | Logger log = Logger.getLogger(DemoResource.class.getName()); 44 | log.log(Level.INFO, "INFO: OpenShift 3 is an excellent platform for JEE development."); 45 | return new String("{\"response\":\"An informational message was recorded internally.\"}"); 46 | } 47 | 48 | @GET 49 | @Path("log/warning") 50 | @Produces({"application/json"}) 51 | public String logWarning(@Context SecurityContext context) { 52 | Logger log = Logger.getLogger(DemoResource.class.getName()); 53 | log.log(Level.WARNING, "WARN: Flying a kite in a thunderstorm should not be attempted."); 54 | return new String("{\"response\":\"A warning message was recorded internally.\"}"); 55 | } 56 | 57 | @GET 58 | @Path("log/error/") 59 | @Produces({"application/json"}) 60 | public String logSevere(@Context SecurityContext context) { 61 | Logger log = Logger.getLogger(DemoResource.class.getName()); 62 | log.log(Level.SEVERE, "ERROR: Something pretty bad has happened and should probably be addressed sooner or later."); 63 | return new String("{\"response\":\"An internal error has occured!\"}"); 64 | } 65 | 66 | // this endpoint will toggle the health of this instance 67 | @GET 68 | @Path("togglehealth/") 69 | @Produces({"application/json"}) 70 | public String togglehealth(@Context SecurityContext context) { 71 | // check if currently healthy, otherwise "become" healthy 72 | if (health == 1) { 73 | // become unhealthy 74 | health = 0; 75 | Logger log = Logger.getLogger(DemoResource.class.getName()); 76 | log.log(Level.SEVERE, "ERROR: I'm not feeling so well."); 77 | return new String("{\"response\":\"The app is starting to look a little ill...\"}"); 78 | } else { 79 | // become healthy 80 | health = 1; 81 | Logger log = Logger.getLogger(DemoResource.class.getName()); 82 | log.log(Level.INFO, "INFO: I feel much better."); 83 | return new String("{\"response\":\"The app is starting to look great!\"}"); 84 | } 85 | } 86 | 87 | @GET 88 | @Path("killswitch/") 89 | @Produces({"application/json"}) 90 | public void killSwitch(@Context SecurityContext context) throws IOException { 91 | Logger log = Logger.getLogger(DemoResource.class.getName()); 92 | log.log(Level.SEVERE, "ERROR: Going down NOW!"); 93 | Runtime.getRuntime().halt(255); 94 | } 95 | 96 | @GET 97 | @Path("healthcheck/") 98 | @Produces({"application/json"}) 99 | public Response checkHealth(@Context SecurityContext context) throws IOException { 100 | 101 | String response = new String("{\"response\":\"Health Status: " + health + "\", \"health\": " + health + "}"); 102 | 103 | // if health is 1, return 200, otherwise 500 104 | if (health == 1) { 105 | return Response.status(Response.Status.OK).entity(response).build(); 106 | } else { 107 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(response).build(); 108 | } 109 | 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/org/jboss/as/quickstarts/tasksrs/model/Resources.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.as.quickstarts.tasksrs.model; 18 | 19 | import java.util.logging.Logger; 20 | 21 | import javax.ejb.Stateful; 22 | import javax.enterprise.context.RequestScoped; 23 | import javax.enterprise.inject.Produces; 24 | import javax.enterprise.inject.spi.InjectionPoint; 25 | import javax.persistence.EntityManager; 26 | import javax.persistence.PersistenceContext; 27 | import javax.persistence.PersistenceContextType; 28 | 29 | /** 30 | * This class uses CDI to alias Java EE resources, such as the persistence context, to CDI beans. As it is a stateful bean, it 31 | * can produce extended persistence contexts. 32 | * 33 | * Example injection on a managed bean field: 34 | * 35 | * @Inject private EntityManager em; 36 | * 37 | * @author Pete Muir 38 | * @author Lukas Fryc 39 | * 40 | */ 41 | @Stateful 42 | @RequestScoped 43 | public class Resources { 44 | 45 | @PersistenceContext(type = PersistenceContextType.EXTENDED) 46 | private EntityManager em; 47 | 48 | @Produces 49 | public EntityManager getEm() { 50 | return em; 51 | } 52 | 53 | @Produces 54 | public Logger getLogger(InjectionPoint ip) { 55 | String category = ip.getMember().getDeclaringClass().getName(); 56 | return Logger.getLogger(category); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/jboss/as/quickstarts/tasksrs/model/Task.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.as.quickstarts.tasksrs.model; 18 | 19 | // JSON: uncomment to include json support (note json is not part of the JAX-RS standard) 20 | import org.codehaus.jackson.annotate.JsonIgnore; 21 | 22 | import static javax.persistence.GenerationType.IDENTITY; 23 | 24 | import java.io.Serializable; 25 | import java.io.StringReader; 26 | 27 | import javax.persistence.Entity; 28 | import javax.persistence.GeneratedValue; 29 | import javax.persistence.Id; 30 | import javax.persistence.ManyToOne; 31 | import javax.xml.bind.JAXB; 32 | import javax.xml.bind.annotation.XmlAttribute; 33 | import javax.xml.bind.annotation.XmlElement; 34 | import javax.xml.bind.annotation.XmlRootElement; 35 | import javax.xml.bind.annotation.XmlTransient; 36 | 37 | /** 38 | * User's task entity which is marked up with JPA annotations and JAXB for serializing XML 39 | * (and JSON if required) 40 | * 41 | * @author Oliver Kiss and others 42 | */ 43 | @SuppressWarnings("serial") 44 | @Entity 45 | @XmlRootElement(name = "task") 46 | public class Task implements Serializable { 47 | 48 | @Id 49 | @GeneratedValue(strategy = IDENTITY) 50 | private Long id; 51 | 52 | @ManyToOne 53 | private User owner; 54 | 55 | private String title; 56 | 57 | public Task() { 58 | } 59 | 60 | public Task(String title) { 61 | super(); 62 | this.title = title; 63 | } 64 | 65 | @XmlAttribute 66 | public Long getId() { 67 | return id; 68 | } 69 | 70 | public void setId(Long id) { 71 | this.id = id; 72 | } 73 | 74 | @XmlTransient 75 | @JsonIgnore 76 | public User getOwner() { 77 | return owner; 78 | } 79 | 80 | @XmlAttribute 81 | public String getOwnerName() { 82 | return owner.getUsername(); 83 | } 84 | 85 | public void setOwner(User owner) { 86 | this.owner = owner; 87 | } 88 | 89 | @XmlElement 90 | public String getTitle() { 91 | return title; 92 | } 93 | 94 | public void setTitle(String title) { 95 | this.title = title; 96 | } 97 | 98 | @Override 99 | public int hashCode() { 100 | final int prime = 31; 101 | int result = 1; 102 | result = prime * result + ((owner == null) ? 0 : owner.hashCode()); 103 | result = prime * result + ((title == null) ? 0 : title.hashCode()); 104 | return result; 105 | } 106 | 107 | @Override 108 | public boolean equals(Object obj) { 109 | if (this == obj) { 110 | return true; 111 | } 112 | if (obj == null) { 113 | return false; 114 | } 115 | if (getClass() != obj.getClass()) { 116 | return false; 117 | } 118 | Task other = (Task) obj; 119 | if (owner == null) { 120 | if (other.owner != null) { 121 | return false; 122 | } 123 | } else if (!owner.equals(other.owner)) { 124 | return false; 125 | } 126 | if (title == null) { 127 | if (other.title != null) { 128 | return false; 129 | } 130 | } else if (!title.equals(other.title)) { 131 | return false; 132 | } 133 | return true; 134 | } 135 | 136 | public static Task stringToTask(String content) { 137 | return JAXB.unmarshal(new StringReader(content), Task.class); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/org/jboss/as/quickstarts/tasksrs/model/TaskDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.as.quickstarts.tasksrs.model; 18 | 19 | import java.util.List; 20 | 21 | import javax.ejb.Local; 22 | 23 | /** 24 | * Basic operations for manipulation of tasks 25 | * 26 | * @author Lukas Fryc 27 | * 28 | */ 29 | @Local 30 | public interface TaskDao { 31 | 32 | void createTask(User user, Task task); 33 | 34 | List getAll(User user); 35 | 36 | List getRange(User user, int offset, int count); 37 | 38 | List getForTitle(User user, String title); 39 | 40 | void deleteTask(Task task); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/jboss/as/quickstarts/tasksrs/model/TaskDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.as.quickstarts.tasksrs.model; 18 | 19 | import java.util.List; 20 | 21 | import javax.ejb.Stateful; 22 | import javax.inject.Inject; 23 | import javax.persistence.EntityManager; 24 | import javax.persistence.TypedQuery; 25 | 26 | /** 27 | * Provides functionality for manipulation with tasks using the persistence context from {@link Resources}. 28 | * 29 | * @author Lukas Fryc 30 | * @author Oliver Kiss 31 | * 32 | */ 33 | @Stateful 34 | public class TaskDaoImpl implements TaskDao { 35 | 36 | @Inject 37 | private EntityManager em; 38 | 39 | @Override 40 | public void createTask(User user, Task task) { 41 | if (!em.contains(user)) { 42 | user = em.merge(user); 43 | } 44 | user.getTasks().add(task); 45 | task.setOwner(user); 46 | em.persist(task); 47 | } 48 | 49 | @Override 50 | public List getAll(User user) { 51 | TypedQuery query = querySelectAllTasksFromUser(user); 52 | return query.getResultList(); 53 | } 54 | 55 | @Override 56 | public List getRange(User user, int offset, int count) { 57 | TypedQuery query = querySelectAllTasksFromUser(user); 58 | query.setMaxResults(count); 59 | query.setFirstResult(offset); 60 | return query.getResultList(); 61 | } 62 | 63 | @Override 64 | public List getForTitle(User user, String title) { 65 | String lowerCaseTitle = "%" + title.toLowerCase() + "%"; 66 | return em.createQuery("SELECT t FROM Task t WHERE t.owner = ?1 AND LOWER(t.title) LIKE ?2", Task.class) 67 | .setParameter(1, user).setParameter(2, lowerCaseTitle).getResultList(); 68 | } 69 | 70 | @Override 71 | public void deleteTask(Task task) { 72 | if (!em.contains(task)) { 73 | task = em.merge(task); 74 | } 75 | em.remove(task); 76 | } 77 | 78 | private TypedQuery querySelectAllTasksFromUser(User user) { 79 | return em.createQuery("SELECT t FROM Task t WHERE t.owner = ?1", Task.class).setParameter(1, user); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/org/jboss/as/quickstarts/tasksrs/model/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.as.quickstarts.tasksrs.model; 18 | 19 | import static javax.persistence.CascadeType.ALL; 20 | import static javax.persistence.GenerationType.IDENTITY; 21 | 22 | import java.io.Serializable; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | import javax.persistence.Column; 27 | import javax.persistence.Entity; 28 | import javax.persistence.GeneratedValue; 29 | import javax.persistence.Id; 30 | import javax.persistence.OneToMany; 31 | import javax.xml.bind.annotation.XmlAttribute; 32 | import javax.xml.bind.annotation.XmlRootElement; 33 | import javax.xml.bind.annotation.XmlTransient; 34 | 35 | import org.codehaus.jackson.annotate.JsonIgnore; 36 | 37 | /** 38 | * User entity 39 | * 40 | * @author Oliver Kiss 41 | */ 42 | @SuppressWarnings("serial") 43 | @Entity 44 | @XmlRootElement(name = "user") 45 | public class User implements Serializable { 46 | 47 | @Id 48 | @GeneratedValue(strategy = IDENTITY) 49 | private Long id; 50 | 51 | @Column(unique = true) 52 | private String username; 53 | 54 | @OneToMany(cascade = ALL, mappedBy = "owner") 55 | @Column(updatable = false) 56 | private List tasks = new ArrayList(); 57 | 58 | public User() { 59 | } 60 | 61 | public User(String username) { 62 | this.username = username; 63 | } 64 | 65 | @XmlAttribute 66 | public Long getId() { 67 | return id; 68 | } 69 | 70 | public void setId(Long id) { 71 | this.id = id; 72 | } 73 | 74 | @XmlAttribute 75 | public String getUsername() { 76 | return username; 77 | } 78 | 79 | public void setUsername(String username) { 80 | this.username = username; 81 | } 82 | 83 | @XmlTransient 84 | @JsonIgnore 85 | public List getTasks() { 86 | return tasks; 87 | } 88 | 89 | public void setTasks(List tasks) { 90 | this.tasks = tasks; 91 | } 92 | 93 | @Override 94 | public int hashCode() { 95 | final int prime = 31; 96 | int result = 1; 97 | result = prime * result + ((username == null) ? 0 : username.hashCode()); 98 | return result; 99 | } 100 | 101 | @Override 102 | public boolean equals(Object obj) { 103 | if (this == obj) 104 | return true; 105 | if (obj == null) 106 | return false; 107 | if (getClass() != obj.getClass()) 108 | return false; 109 | User other = (User) obj; 110 | if (username == null) { 111 | if (other.username != null) 112 | return false; 113 | } else if (!username.equals(other.username)) 114 | return false; 115 | return true; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/org/jboss/as/quickstarts/tasksrs/model/UserDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.as.quickstarts.tasksrs.model; 18 | 19 | import java.util.List; 20 | 21 | import javax.ejb.Local; 22 | 23 | /** 24 | * Basic operations for manipulation with users 25 | * 26 | * @author Lukas Fryc 27 | * 28 | */ 29 | @Local 30 | public interface UserDao { 31 | 32 | public User getForUsername(String username); 33 | 34 | public void createUser(User user); 35 | 36 | public List getAll(); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/jboss/as/quickstarts/tasksrs/model/UserDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.as.quickstarts.tasksrs.model; 18 | 19 | import java.util.List; 20 | 21 | import javax.ejb.Stateful; 22 | import javax.inject.Inject; 23 | import javax.persistence.EntityManager; 24 | 25 | /** 26 | * Provides functionality for manipulation with users using persistence context from {@link Resources}. 27 | * 28 | * @author Lukas Fryc 29 | * @author Oliver Kiss 30 | * 31 | */ 32 | @Stateful 33 | public class UserDaoImpl implements UserDao { 34 | 35 | @Inject 36 | private EntityManager em; 37 | 38 | public User getForUsername(String username) { 39 | List result = em.createQuery("select u from User u where u.username = ?1", User.class).setParameter(1, username) 40 | .getResultList(); 41 | 42 | if (result.isEmpty()) { 43 | return null; 44 | } 45 | return result.get(0); 46 | } 47 | 48 | public List getAll() { 49 | return em.createQuery("select u from User u", User.class).getResultList(); 50 | } 51 | 52 | public void createUser(User user) { 53 | em.persist(user); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/jboss/as/quickstarts/tasksrs/service/TaskResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.as.quickstarts.tasksrs.service; 18 | 19 | import java.net.URI; 20 | import java.security.Principal; 21 | import java.util.List; 22 | 23 | import javax.inject.Inject; 24 | import javax.ws.rs.DELETE; 25 | import javax.ws.rs.DefaultValue; 26 | import javax.ws.rs.GET; 27 | import javax.ws.rs.POST; 28 | import javax.ws.rs.Path; 29 | import javax.ws.rs.PathParam; 30 | import javax.ws.rs.Produces; 31 | import javax.ws.rs.WebApplicationException; 32 | import javax.ws.rs.core.Context; 33 | import javax.ws.rs.core.Response; 34 | import javax.ws.rs.core.SecurityContext; 35 | import javax.ws.rs.core.UriBuilder; 36 | import javax.ws.rs.core.UriInfo; 37 | 38 | import org.jboss.as.quickstarts.tasksrs.model.Task; 39 | import org.jboss.as.quickstarts.tasksrs.model.TaskDao; 40 | import org.jboss.as.quickstarts.tasksrs.model.User; 41 | import org.jboss.as.quickstarts.tasksrs.model.UserDao; 42 | 43 | /** 44 | * A JAX-RS resource for exposing REST endpoints for Task manipulation 45 | */ 46 | @Path("/") 47 | public class TaskResource { 48 | @Inject 49 | private UserDao userDao; 50 | 51 | @Inject 52 | private TaskDao taskDao; 53 | 54 | @POST 55 | @Path("tasks/{title}") 56 | public Response createTask(@Context UriInfo info, @Context SecurityContext context, 57 | @PathParam("title") @DefaultValue("task") String taskTitle) { 58 | User user = getUser(context); 59 | Task task = new Task(taskTitle); 60 | 61 | taskDao.createTask(user, task); 62 | 63 | // Construct the URI for the newly created resource and put in into the Location header of the response 64 | // (assumes that there is only one occurrence of the task title in the request) 65 | String rawPath = info.getAbsolutePath().getRawPath().replace(task.getTitle(), task.getId().toString()); 66 | UriBuilder uriBuilder = info.getAbsolutePathBuilder().replacePath(rawPath); 67 | URI uri = uriBuilder.build(); 68 | 69 | return Response.created(uri).build(); 70 | } 71 | 72 | @DELETE 73 | @Path("tasks/{id}") 74 | public void deleteTaskById(@Context SecurityContext context, @PathParam("id") Long id) { 75 | Task task = getTaskById(context, id); 76 | 77 | taskDao.deleteTask(task); 78 | } 79 | 80 | @GET 81 | @Path("tasks/{id}") 82 | @Produces({ "application/xml", "application/json" }) 83 | public Task getTaskById(@Context SecurityContext context, @PathParam("id") Long id) { 84 | User user = getUser(context); 85 | 86 | return getTask(user, id); 87 | } 88 | 89 | @GET 90 | @Path("tasks/{title}") 91 | @Produces({ "application/xml", "application/json" }) 92 | public List getTasksByTitle(@Context SecurityContext context, @PathParam("title") String title) { 93 | return getTasks(getUser(context), title); 94 | } 95 | 96 | @GET 97 | @Path("tasks") 98 | @Produces({ "application/xml", "application/json" }) 99 | public List getTasks(@Context SecurityContext context) { 100 | return getTasks(getUser(context)); 101 | } 102 | 103 | // Utility Methods 104 | 105 | private List getTasks(User user, String title) { 106 | return taskDao.getForTitle(user, title); 107 | } 108 | 109 | private List getTasks(User user) { 110 | return taskDao.getAll(user); 111 | } 112 | 113 | private Task getTask(User user, Long id) { 114 | for (Task task : taskDao.getAll(user)) 115 | if (task.getId().equals(id)) 116 | return task; 117 | 118 | throw new WebApplicationException(Response.Status.NOT_FOUND); 119 | } 120 | 121 | private User getUser(SecurityContext context) { 122 | Principal principal = null; 123 | 124 | if (context != null) 125 | principal = context.getUserPrincipal(); 126 | 127 | if (principal == null) 128 | throw new WebApplicationException(Response.Status.UNAUTHORIZED); 129 | 130 | return getUser(principal.getName()); 131 | } 132 | 133 | private User getUser(String username) { 134 | 135 | try { 136 | User user = userDao.getForUsername(username); 137 | 138 | if (user == null) { 139 | user = new User(username); 140 | 141 | userDao.createUser(user); 142 | } 143 | 144 | return user; 145 | } catch (Exception e) { 146 | throw new WebApplicationException(e); 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/org/jboss/as/quickstarts/tasksrs/service/UserResource.java: -------------------------------------------------------------------------------- 1 | package org.jboss.as.quickstarts.tasksrs.service; 2 | 3 | import java.util.Collections; 4 | import java.util.Comparator; 5 | import java.util.List; 6 | 7 | import javax.inject.Inject; 8 | import javax.ws.rs.GET; 9 | import javax.ws.rs.Path; 10 | import javax.ws.rs.Produces; 11 | 12 | import org.jboss.as.quickstarts.tasksrs.model.User; 13 | import org.jboss.as.quickstarts.tasksrs.model.UserDao; 14 | 15 | /** 16 | * A JAX-RS resource for exposing REST endpoints for User manipulation 17 | */ 18 | 19 | @Path("/users") 20 | public class UserResource { 21 | @Inject 22 | private UserDao userDao; 23 | 24 | @GET 25 | @Path("/") 26 | @Produces({ "application/xml", "application/json" }) 27 | public List getUsers() { 28 | List users = userDao.getAll(); 29 | 30 | // TODO: Uncomment to sort users based on number of tasks 31 | 32 | // Collections.sort(users, new Comparator() { 33 | // 34 | // @Override 35 | // public int compare(User user1, User user2) { 36 | // return Integer.compare(user2.getTasks().size(), user1.getTasks().size()); 37 | // } 38 | // }); 39 | 40 | return users; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 23 | 24 | java:jboss/datasources/TasksRsQuickstartDS 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 17 | 21 | 22 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/tasks-rs-ds.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 22 | 25 | 27 | 30 | jdbc:h2:mem:tasks-rs-xml-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1 31 | h2 32 | 33 | sa 34 | sa 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 21 | 22 | 23 | javax.ws.rs.core.Application 24 | /ws/* 25 | 26 | 27 | 28 | 29 | BASIC 30 | RealmUsersRoles 31 | 32 | 33 | 34 | resteasy.role.based.security 35 | true 36 | 37 | 38 | 39 | 40 | Tasks 41 | /ws/tasks/* 42 | 43 | 44 | Users 45 | /ws/users/* 46 | 47 | 48 | 49 | guest 50 | 51 | 52 | 53 | 54 | guest 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/main/webapp/css/styles-additions.css: -------------------------------------------------------------------------------- 1 | patternfly-additions.css -------------------------------------------------------------------------------- /src/main/webapp/css/styles-additions.min.css: -------------------------------------------------------------------------------- 1 | patternfly-additions.min.css -------------------------------------------------------------------------------- /src/main/webapp/css/styles.css: -------------------------------------------------------------------------------- 1 | patternfly.css -------------------------------------------------------------------------------- /src/main/webapp/css/styles.min.css: -------------------------------------------------------------------------------- 1 | patternfly.min.css -------------------------------------------------------------------------------- /src/main/webapp/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Bold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Bold-webfont.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Bold-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Bold-webfont.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Bold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Bold-webfont.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-BoldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-BoldItalic-webfont.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-BoldItalic-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-BoldItalic-webfont.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-BoldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-BoldItalic-webfont.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-ExtraBold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-ExtraBold-webfont.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-ExtraBold-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-ExtraBold-webfont.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-ExtraBold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-ExtraBold-webfont.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-ExtraBoldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-ExtraBoldItalic-webfont.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-ExtraBoldItalic-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-ExtraBoldItalic-webfont.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-ExtraBoldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-ExtraBoldItalic-webfont.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Italic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Italic-webfont.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Italic-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Italic-webfont.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Italic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Italic-webfont.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Light-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Light-webfont.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Light-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Light-webfont.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Light-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Light-webfont.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-LightItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-LightItalic-webfont.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-LightItalic-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-LightItalic-webfont.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-LightItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-LightItalic-webfont.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Regular-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Regular-webfont.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Regular-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Regular-webfont.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Regular-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Regular-webfont.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Semibold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Semibold-webfont.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Semibold-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Semibold-webfont.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-Semibold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-Semibold-webfont.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-SemiboldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-SemiboldItalic-webfont.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-SemiboldItalic-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-SemiboldItalic-webfont.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/OpenSans-SemiboldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/OpenSans-SemiboldItalic-webfont.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/PatternFlyIcons-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/PatternFlyIcons-webfont.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/PatternFlyIcons-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/PatternFlyIcons-webfont.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/PatternFlyIcons-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/PatternFlyIcons-webfont.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /src/main/webapp/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /src/main/webapp/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /src/main/webapp/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /src/main/webapp/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /src/main/webapp/img/OpenShift-Logo-NoText.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 22 | 23 | 25 | 26 | 27 | 29 | 30 | 31 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/main/webapp/img/OpenShift-Logo-Text.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 24 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 67 | 72 | 73 | 76 | 77 | 78 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/main/webapp/img/OpenShift-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | image/svg+xml 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/main/webapp/img/RH_Atomic-Logo-NoText.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 11 | 12 | 13 | 15 | 17 | 32 | 35 | 36 | 37 | 39 | 41 | 43 | 45 | 46 | 47 | 48 | 49 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/main/webapp/img/RH_Atomic-Logo-Text.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 11 | 12 | 13 | 14 | 16 | 19 | 34 | 37 | 38 | 39 | 41 | 43 | 45 | 47 | 48 | 49 | 50 | 51 | 53 | 54 | 55 | 56 | 59 | 60 | 64 | 65 | 67 | 68 | 70 | 71 | 77 | 82 | 83 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /src/main/webapp/img/RH_atomic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 13 | 28 | 31 | 32 | 33 | 36 | 38 | 40 | 42 | 43 | 44 | 46 | 48 | 51 | 52 | 53 | 54 | 57 | 58 | 62 | 63 | 65 | 66 | 68 | 69 | 75 | 80 | 81 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /src/main/webapp/img/apple-touch-icon-precomposed-114.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/apple-touch-icon-precomposed-114.png -------------------------------------------------------------------------------- /src/main/webapp/img/apple-touch-icon-precomposed-144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/apple-touch-icon-precomposed-144.png -------------------------------------------------------------------------------- /src/main/webapp/img/apple-touch-icon-precomposed-152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/apple-touch-icon-precomposed-152.png -------------------------------------------------------------------------------- /src/main/webapp/img/apple-touch-icon-precomposed-180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/apple-touch-icon-precomposed-180.png -------------------------------------------------------------------------------- /src/main/webapp/img/apple-touch-icon-precomposed-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/apple-touch-icon-precomposed-57.png -------------------------------------------------------------------------------- /src/main/webapp/img/apple-touch-icon-precomposed-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/apple-touch-icon-precomposed-72.png -------------------------------------------------------------------------------- /src/main/webapp/img/apple-touch-icon-precomposed-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/apple-touch-icon-precomposed-76.png -------------------------------------------------------------------------------- /src/main/webapp/img/bg-login.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/bg-login.jpg -------------------------------------------------------------------------------- /src/main/webapp/img/bg-navbar-pf-alt.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/webapp/img/brand-alt.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 12 | 13 | 14 | 18 | 22 | 26 | 27 | 35 | 36 | 39 | 43 | 47 | 48 | 49 | 54 | 56 | 57 | 58 | 64 | 67 | 68 | 69 | 72 | 75 | 76 | 77 | 78 | 81 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /src/main/webapp/img/brand.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 12 | 13 | 14 | 18 | 22 | 26 | 27 | 35 | 36 | 38 | 42 | 46 | 47 | 48 | 53 | 55 | 56 | 57 | 63 | 66 | 67 | 68 | 71 | 74 | 75 | 76 | 77 | 80 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /src/main/webapp/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/favicon.ico -------------------------------------------------------------------------------- /src/main/webapp/img/kubernetes-Logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 11 | 12 | 15 | 20 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/main/webapp/img/kubernetes.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/main/webapp/img/logo-alt.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 18 | 19 | -------------------------------------------------------------------------------- /src/main/webapp/img/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/webapp/img/spinner-inverse-lg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/spinner-inverse-lg.gif -------------------------------------------------------------------------------- /src/main/webapp/img/spinner-inverse-sm.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/spinner-inverse-sm.gif -------------------------------------------------------------------------------- /src/main/webapp/img/spinner-inverse-xs.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/spinner-inverse-xs.gif -------------------------------------------------------------------------------- /src/main/webapp/img/spinner-inverse.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/spinner-inverse.gif -------------------------------------------------------------------------------- /src/main/webapp/img/spinner-lg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/spinner-lg.gif -------------------------------------------------------------------------------- /src/main/webapp/img/spinner-sm.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/spinner-sm.gif -------------------------------------------------------------------------------- /src/main/webapp/img/spinner-xs.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/spinner-xs.gif -------------------------------------------------------------------------------- /src/main/webapp/img/spinner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/img/spinner.gif -------------------------------------------------------------------------------- /src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | OpenShift Demo Tasks 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 56 |
57 |
58 |
59 |
60 |
61 |

62 | Logger 63 |

64 |
65 |
66 |
67 |

68 | 69 |

70 |

71 | 72 |

73 |

74 | 75 |

76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |

84 | Load Generator 85 |

86 |
87 |
88 |
89 |
90 | 91 |
92 | 93 |
94 |
95 |
96 |
97 | 98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |

108 | Danger Zone 109 |

110 |
111 |
112 |
113 |
114 |
115 | UNKNOWN 116 |
117 |
118 |

119 | 120 |

121 |

122 | 123 |

124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |

134 | Info 135 |

136 |
137 |
138 |
139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | <% int mb = 1024*1024; %> 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |

166 | Messages 167 |

168 |
169 |
170 |
171 |

Nothing to report.

172 |
173 |
174 |
175 |
176 |
177 |
178 | 179 | 279 | 280 | -------------------------------------------------------------------------------- /src/main/webapp/js/demo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenShiftDemos/openshift-tasks/a40e60cad0fd5312aa0034253d4a64e84137de8a/src/main/webapp/js/demo.js -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.apache.maven.skins 4 | maven-fluido-skin 5 | 1.5 6 | 7 | 8 | OpenShift CI/CD Demo 9 | https://www.openshift.com/content/subdomain/openshift-logo-horizontal.svg 10 | http://www.openshift.com 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/test/java/org/jboss/as/quickstarts/tasksrs/DefaultDeployment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.as.quickstarts.tasksrs; 18 | 19 | import java.io.File; 20 | 21 | import org.jboss.shrinkwrap.api.ShrinkWrap; 22 | import org.jboss.shrinkwrap.api.spec.WebArchive; 23 | 24 | /** 25 | * Enables prepare project-specific {@link WebArchive} for deployment. 26 | * 27 | * @author Lukas Fryc 28 | * 29 | */ 30 | public class DefaultDeployment { 31 | 32 | private static final String WEBAPP_SRC = "src/main/webapp"; 33 | 34 | private WebArchive webArchive; 35 | 36 | public DefaultDeployment() { 37 | webArchive = ShrinkWrap.create(WebArchive.class, "test.war").addAsWebInfResource( 38 | new File(WEBAPP_SRC, "WEB-INF/beans.xml")); 39 | } 40 | 41 | public DefaultDeployment withPersistence() { 42 | webArchive = webArchive.addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml").addAsWebInfResource( 43 | "test-ds.xml", "test-ds.xml"); 44 | return this; 45 | } 46 | 47 | public DefaultDeployment withImportedData() { 48 | webArchive = webArchive.addAsResource("import.sql"); 49 | return this; 50 | } 51 | 52 | public WebArchive getArchive() { 53 | return webArchive; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/jboss/as/quickstarts/tasksrs/TaskDaoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.as.quickstarts.tasksrs; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertTrue; 21 | 22 | import java.io.FileNotFoundException; 23 | import java.util.List; 24 | 25 | import javax.inject.Inject; 26 | import javax.persistence.EntityManager; 27 | 28 | import org.jboss.arquillian.container.test.api.Deployment; 29 | import org.jboss.arquillian.junit.Arquillian; 30 | import org.jboss.arquillian.junit.InSequence; 31 | import org.jboss.as.quickstarts.tasksrs.category.IntegrationTest; 32 | import org.jboss.as.quickstarts.tasksrs.model.*; 33 | import org.jboss.shrinkwrap.api.spec.WebArchive; 34 | import org.junit.Before; 35 | import org.junit.Test; 36 | import org.junit.experimental.categories.Category; 37 | import org.junit.runner.RunWith; 38 | 39 | /** 40 | * @author Lukas Fryc 41 | * @author Oliver Kiss 42 | */ 43 | @RunWith(Arquillian.class) 44 | @Category(IntegrationTest.class) 45 | public class TaskDaoTest { 46 | 47 | @Deployment 48 | public static WebArchive deployment() throws IllegalArgumentException, FileNotFoundException { 49 | return new DefaultDeployment().withPersistence().withImportedData().getArchive() 50 | .addClasses(Resources.class, User.class, UserDao.class, Task.class, TaskDao.class, TaskDaoImpl.class); 51 | } 52 | 53 | @Inject 54 | private EntityManager em; 55 | 56 | @Inject 57 | private TaskDao taskDao; 58 | 59 | private User detachedUser; 60 | 61 | @Before 62 | public void setUp() throws Exception { 63 | detachedUser = new User("jdoe"); 64 | detachedUser.setId(1L); 65 | } 66 | 67 | @Test 68 | @InSequence(1) 69 | public void user_should_be_created_with_one_task_attached() throws Exception { 70 | // given 71 | User user = new User("New user"); 72 | Task task = new Task("New task"); 73 | 74 | // when 75 | em.persist(user); 76 | taskDao.createTask(user, task); 77 | List userTasks = em.createQuery("SELECT t FROM Task t WHERE t.owner = :owner", Task.class) 78 | .setParameter("owner", user).getResultList(); 79 | 80 | // then 81 | assertEquals(1, userTasks.size()); 82 | assertEquals(task, userTasks.get(0)); 83 | } 84 | 85 | @Test 86 | @InSequence(2) 87 | public void all_tasks_should_be_obtained_from_detachedUser() { 88 | // when 89 | List userTasks = taskDao.getAll(detachedUser); 90 | 91 | // then 92 | assertEquals(2, userTasks.size()); 93 | } 94 | 95 | @Test 96 | @InSequence(3) 97 | public void range_of_tasks_should_be_provided_by_taskDao() { 98 | // when 99 | List headOfTasks = taskDao.getRange(detachedUser, 0, 1); 100 | List tailOfTasks = taskDao.getRange(detachedUser, 1, 1); 101 | 102 | // then 103 | assertEquals(1, headOfTasks.size()); 104 | assertEquals(1, tailOfTasks.size()); 105 | assertTrue(headOfTasks.get(0).getTitle().contains("first")); 106 | assertTrue(tailOfTasks.get(0).getTitle().contains("second")); 107 | } 108 | 109 | @Test 110 | @InSequence(4) 111 | public void taskDao_should_provide_basic_case_insensitive_full_text_search() { 112 | // given 113 | String taskTitlePart = "FIRST"; 114 | 115 | // when 116 | List titledTasks = taskDao.getForTitle(detachedUser, taskTitlePart); 117 | 118 | // then 119 | assertEquals(1, titledTasks.size()); 120 | assertTrue(titledTasks.get(0).getTitle().contains("first")); 121 | } 122 | 123 | @Test 124 | @InSequence(5) 125 | public void taskDao_should_remove_task_from_detachedUser() { 126 | // given 127 | Task task = new Task(); 128 | task.setId(1L); 129 | task.setOwner(detachedUser); 130 | assertEquals(2, taskDao.getAll(detachedUser).size()); 131 | 132 | // when 133 | taskDao.deleteTask(task); 134 | 135 | // then 136 | assertEquals(1, taskDao.getAll(detachedUser).size()); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/test/java/org/jboss/as/quickstarts/tasksrs/UserDaoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.as.quickstarts.tasksrs; 18 | 19 | import static org.junit.Assert.assertNull; 20 | import static org.junit.Assert.assertTrue; 21 | 22 | import java.io.FileNotFoundException; 23 | 24 | import javax.inject.Inject; 25 | import javax.persistence.EntityManager; 26 | 27 | import org.jboss.arquillian.container.test.api.Deployment; 28 | import org.jboss.arquillian.junit.Arquillian; 29 | import org.jboss.as.quickstarts.tasksrs.category.IntegrationTest; 30 | import org.jboss.as.quickstarts.tasksrs.model.*; 31 | import org.jboss.shrinkwrap.api.spec.WebArchive; 32 | import org.junit.Assert; 33 | import org.junit.Test; 34 | import org.junit.experimental.categories.Category; 35 | import org.junit.runner.RunWith; 36 | 37 | /** 38 | * @author Lukas Fryc 39 | * @author Oliver Kiss 40 | */ 41 | @RunWith(Arquillian.class) 42 | @Category(IntegrationTest.class) 43 | public class UserDaoTest { 44 | 45 | @Deployment 46 | public static WebArchive deployment() throws IllegalArgumentException, FileNotFoundException { 47 | return new DefaultDeployment().withPersistence().withImportedData().getArchive() 48 | .addClasses(Resources.class, User.class, UserDao.class, Task.class, TaskDao.class, UserDaoImpl.class); 49 | } 50 | 51 | @Inject 52 | private UserDao userDao; 53 | 54 | @Inject 55 | private EntityManager em; 56 | 57 | @Test 58 | public void userDao_should_create_user_so_it_could_be_retrieved_from_userDao_by_username() { 59 | // given 60 | User created = new User("username1"); 61 | 62 | // when 63 | userDao.createUser(created); 64 | User retrieved = userDao.getForUsername("username1"); 65 | 66 | // then 67 | assertTrue(em.contains(created)); 68 | assertTrue(em.contains(retrieved)); 69 | Assert.assertEquals(created, retrieved); 70 | } 71 | 72 | @Test 73 | public void user_should_be_retrievable_from_userDao_by_username() { 74 | // given 75 | String username = "jdoe"; 76 | 77 | // when 78 | User retrieved = userDao.getForUsername(username); 79 | 80 | // then 81 | Assert.assertEquals(username, retrieved.getUsername()); 82 | } 83 | 84 | @Test 85 | public void userDao_should_return_null_when_searching_for_non_existent_user() { 86 | // given 87 | String nonExistent = "nonExistent"; 88 | 89 | // when 90 | User retrieved = userDao.getForUsername(nonExistent); 91 | 92 | // then 93 | assertNull(retrieved); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/test/java/org/jboss/as/quickstarts/tasksrs/category/IntegrationTest.java: -------------------------------------------------------------------------------- 1 | package org.jboss.as.quickstarts.tasksrs.category; 2 | 3 | public interface IntegrationTest { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/org/jboss/as/quickstarts/tasksrs/category/UnitTest.java: -------------------------------------------------------------------------------- 1 | package org.jboss.as.quickstarts.tasksrs.category; 2 | 3 | public interface UnitTest { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/org/jboss/as/quickstarts/tasksrs/service/TaskResourceTest.java: -------------------------------------------------------------------------------- 1 | package org.jboss.as.quickstarts.tasksrs.service; 2 | 3 | import static java.util.Arrays.asList; 4 | import static org.mockito.Matchers.any; 5 | import static org.mockito.Matchers.anyString; 6 | import static org.mockito.Mockito.mock; 7 | import static org.mockito.Mockito.verify; 8 | import static org.mockito.Mockito.when; 9 | 10 | import java.net.URI; 11 | import java.net.URISyntaxException; 12 | import java.security.Principal; 13 | 14 | import javax.ws.rs.core.SecurityContext; 15 | import javax.ws.rs.core.UriBuilder; 16 | import javax.ws.rs.core.UriInfo; 17 | 18 | import org.jboss.as.quickstarts.tasksrs.category.UnitTest; 19 | import org.jboss.as.quickstarts.tasksrs.model.Task; 20 | import org.jboss.as.quickstarts.tasksrs.model.TaskDao; 21 | import org.jboss.as.quickstarts.tasksrs.model.User; 22 | import org.jboss.as.quickstarts.tasksrs.model.UserDao; 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | import org.junit.experimental.categories.Category; 26 | import org.junit.runner.RunWith; 27 | import org.mockito.InjectMocks; 28 | import org.mockito.Mock; 29 | import org.mockito.Mockito; 30 | import org.mockito.invocation.InvocationOnMock; 31 | import org.mockito.runners.MockitoJUnitRunner; 32 | import org.mockito.stubbing.Answer; 33 | 34 | @RunWith(MockitoJUnitRunner.class) 35 | @Category(UnitTest.class) 36 | public class TaskResourceTest { 37 | @InjectMocks 38 | private TaskResource taskResource; 39 | 40 | @Mock 41 | private UserDao userDao; 42 | 43 | @Mock 44 | private TaskDao taskDao; 45 | 46 | @Mock 47 | private SecurityContext securityContext; 48 | 49 | @Mock 50 | private UriInfo uriInfo; 51 | 52 | @Before 53 | public void setupMocks() throws URISyntaxException { 54 | Principal principal = mock(Principal.class); 55 | when(securityContext.getUserPrincipal()).thenReturn(principal); 56 | when(principal.getName()).thenReturn("sally"); 57 | 58 | 59 | // mock response 60 | URI uri = new URI("/response"); 61 | UriBuilder uriBuilder = mock(UriBuilder.class); 62 | when(uriInfo.getAbsolutePath()).thenReturn(uri); 63 | when(uriInfo.getAbsolutePathBuilder()).thenReturn(uriBuilder); 64 | when(uriBuilder.replacePath(anyString())).thenReturn(uriBuilder); 65 | when(uriBuilder.build()).thenReturn(uri); 66 | 67 | // set id on new tasks 68 | Mockito.doAnswer(new Answer() { 69 | @Override 70 | public Object answer(InvocationOnMock invocation) throws Throwable { 71 | Task task = (Task)invocation.getArgument(1); 72 | task.setId(System.currentTimeMillis()); 73 | return null; 74 | } 75 | }).when(taskDao).createTask(any(User.class), any(Task.class)); 76 | } 77 | 78 | 79 | @Test 80 | public void createTaskWithNewUser() { 81 | taskResource.createTask(uriInfo, securityContext, "run a demo!"); 82 | 83 | verify(userDao).createUser(any(User.class)); 84 | verify(taskDao).createTask(any(User.class), any(Task.class)); 85 | } 86 | 87 | 88 | @Test 89 | public void getTaskByIdWithNonExistingUser() { 90 | when(taskDao.getAll(any(User.class))).thenReturn(asList(newTask(123L))); 91 | 92 | taskResource.getTaskById(securityContext, 123L); 93 | 94 | verify(userDao).getForUsername("sally"); 95 | verify(userDao).createUser(any(User.class)); 96 | verify(taskDao).getAll(any(User.class)); 97 | } 98 | 99 | 100 | @Test 101 | public void deleteTaskById() { 102 | when(taskDao.getAll(any(User.class))).thenReturn(asList(newTask(123L))); 103 | 104 | taskResource.deleteTaskById(securityContext, 123L); 105 | 106 | verify(userDao).getForUsername("sally"); 107 | verify(userDao).createUser(any(User.class)); 108 | verify(taskDao).getAll(any(User.class)); 109 | verify(taskDao).deleteTask(any(Task.class)); 110 | 111 | } 112 | 113 | private Task newTask(Long id) { 114 | Task task = new Task("Task 1"); 115 | task.setId(id); 116 | return task; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/test/java/org/jboss/as/quickstarts/tasksrs/service/UserResourceTest.java: -------------------------------------------------------------------------------- 1 | package org.jboss.as.quickstarts.tasksrs.service; 2 | 3 | import static java.lang.System.currentTimeMillis; 4 | import static java.util.Arrays.asList; 5 | import static org.junit.Assert.assertEquals; 6 | import static org.mockito.Mockito.verify; 7 | 8 | import java.util.LinkedList; 9 | import java.util.List; 10 | 11 | import org.jboss.as.quickstarts.tasksrs.category.UnitTest; 12 | import org.jboss.as.quickstarts.tasksrs.model.Task; 13 | import org.jboss.as.quickstarts.tasksrs.model.User; 14 | import org.jboss.as.quickstarts.tasksrs.model.UserDao; 15 | import org.junit.Before; 16 | import org.junit.Ignore; 17 | import org.junit.Test; 18 | import org.junit.experimental.categories.Category; 19 | import org.junit.runner.RunWith; 20 | import org.mockito.InjectMocks; 21 | import org.mockito.Mock; 22 | import org.mockito.Mockito; 23 | import org.mockito.runners.MockitoJUnitRunner; 24 | 25 | 26 | @RunWith(MockitoJUnitRunner.class) 27 | @Category(UnitTest.class) 28 | public class UserResourceTest { 29 | @InjectMocks 30 | private UserResource userResource; 31 | 32 | @Mock 33 | private UserDao userDao; 34 | 35 | @Before 36 | public void setupMocks() { 37 | List users = new LinkedList<>(); 38 | users.add(newUser("user1", randomTasks(1))); 39 | users.add(newUser("user2", randomTasks(5))); 40 | users.add(newUser("user3", randomTasks(3))); 41 | 42 | Mockito.when(userDao.getAll()).thenReturn(users); 43 | } 44 | 45 | @Test 46 | // TODO: comment out to make the test run 47 | @Ignore 48 | public void getUsersSortedByTask() { 49 | List users = userResource.getUsers(); 50 | 51 | verify(userDao).getAll(); 52 | 53 | assertEquals("user2", users.get(0).getUsername()); 54 | assertEquals("user3", users.get(1).getUsername()); 55 | assertEquals("user1", users.get(2).getUsername()); 56 | 57 | } 58 | 59 | 60 | // helper methods 61 | 62 | private User newUser(String username, Task...tasks) { 63 | User user = new User(); 64 | user.setId(currentTimeMillis()); 65 | user.setUsername(username); 66 | user.setTasks(asList(tasks)); 67 | return user; 68 | } 69 | 70 | private Task[] randomTasks(int count) { 71 | List tasks = new LinkedList<>(); 72 | for (int i = 0; i < count; i++) { 73 | Task task = new Task(); 74 | task.setId(i * 1L); 75 | task.setTitle("Task " + i); 76 | tasks.add(task); 77 | } 78 | 79 | return tasks.toArray(new Task[tasks.size()]); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/resources/META-INF/test-persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 23 | 24 | 27 | 29 | java:jboss/datasources/TasksRsQuickstartTestDS 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/test/resources/arquillian.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/test/resources/import.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- JBoss, Home of Professional Open Source 3 | -- Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | -- contributors by the @authors tag. See the copyright.txt in the 5 | -- distribution for a full listing of individual contributors. 6 | -- 7 | -- Licensed under the Apache License, Version 2.0 (the "License"); 8 | -- you may not use this file except in compliance with the License. 9 | -- You may obtain a copy of the License at 10 | -- http://www.apache.org/licenses/LICENSE-2.0 11 | -- Unless required by applicable law or agreed to in writing, software 12 | -- distributed under the License is distributed on an "AS IS" BASIS, 13 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | -- See the License for the specific language governing permissions and 15 | -- limitations under the License. 16 | -- 17 | 18 | BEGIN 19 | INSERT INTO User (ID, USERNAME) VALUES (1, 'jdoe'); 20 | INSERT INTO User (ID, USERNAME) VALUES (2, 'emuster'); 21 | COMMIT 22 | 23 | BEGIN 24 | INSERT INTO Task (ID, OWNER_ID, TITLE) VALUES (1, 1, 'johns first task'); 25 | INSERT INTO Task (ID, OWNER_ID, TITLE) VALUES (2, 1, 'johns second task'); 26 | COMMIT 27 | -------------------------------------------------------------------------------- /src/test/resources/test-ds.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 22 | 25 | 27 | 30 | jdbc:h2:mem:tasks-rs-quickstart-test;DB_CLOSE_DELAY=-1 31 | h2 32 | 33 | sa 34 | sa 35 | 36 | 37 | 38 | --------------------------------------------------------------------------------