File tree Expand file tree Collapse file tree
test/java/works/buddy/samples Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ FROM maven:amazoncorretto as build
2+ WORKDIR /javaapp
3+ COPY . .
4+ RUN mvn clean install
5+
6+ FROM adhig93/tomcat-conf
7+ COPY --from=build /javaapp/target/*.war /usr/local/tomcat/webapps/
Original file line number Diff line number Diff line change 1+ web : java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/* .war
Original file line number Diff line number Diff line change 1+ # Simple Java Project
2+ This is a demo project that you can use with [ Buddy Continuous Deployment] ( https://buddy.works ) .
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" >
4+ <modelVersion >4.0.0</modelVersion >
5+ <groupId >works.buddy.samples</groupId >
6+ <artifactId >works-with-heroku</artifactId >
7+ <version >1.0</version >
8+ <packaging >war</packaging >
9+ <properties >
10+ <maven .compiler.source>1.6</maven .compiler.source>
11+ <maven .compiler.target>1.6</maven .compiler.target>
12+ </properties >
13+ <dependencies >
14+ <dependency >
15+ <groupId >javax.servlet</groupId >
16+ <artifactId >servlet-api</artifactId >
17+ <version >2.5</version >
18+ <scope >provided</scope >
19+ </dependency >
20+ <dependency >
21+ <groupId >junit</groupId >
22+ <artifactId >junit</artifactId >
23+ <version >4.12</version >
24+ <scope >test</scope >
25+ </dependency >
26+ <dependency >
27+ <groupId >org.mockito</groupId >
28+ <artifactId >mockito-all</artifactId >
29+ <version >1.10.19</version >
30+ <scope >test</scope >
31+ </dependency >
32+ </dependencies >
33+
34+ <build >
35+ <plugins >
36+ <plugin >
37+ <groupId >org.apache.maven.plugins</groupId >
38+ <artifactId >maven-dependency-plugin</artifactId >
39+ <version >2.3</version >
40+ <executions >
41+ <execution >
42+ <phase >package</phase >
43+ <goals ><goal >copy</goal ></goals >
44+ <configuration >
45+ <artifactItems >
46+ <artifactItem >
47+ <groupId >org.eclipse.jetty</groupId >
48+ <artifactId >jetty-runner</artifactId >
49+ <version >9.3.3.v20150827</version >
50+ <destFileName >jetty-runner.jar</destFileName >
51+ </artifactItem >
52+ </artifactItems >
53+ </configuration >
54+ </execution >
55+ </executions >
56+ </plugin >
57+ </plugins >
58+ </build >
59+ </project >
Original file line number Diff line number Diff line change 1+ package works .buddy .samples ;
2+
3+ import javax .servlet .ServletException ;
4+ import javax .servlet .http .HttpServlet ;
5+ import javax .servlet .http .HttpServletRequest ;
6+ import javax .servlet .http .HttpServletResponse ;
7+ import java .io .IOException ;
8+ import java .io .PrintWriter ;
9+
10+ public class WorksWithHerokuServlet extends HttpServlet {
11+
12+ protected void doGet (HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException {
13+ response .setContentType ("text/plain" );
14+ response .setStatus (404 );
15+ PrintWriter writer = response .getWriter ();
16+ writer .print ("WEB APP WORKING" );
17+ writer .close ();
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <web-app id =" WebApp_ID" version =" 2.4" xmlns =" http://java.sun.com/xml/ns/j2ee"
3+ xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi:schemaLocation=" http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
5+
6+ <display-name >Works with Heroku</display-name >
7+
8+ <servlet >
9+ <servlet-name >WorksWithHerokuServlet</servlet-name >
10+ <servlet-class >works.buddy.samples.WorksWithHerokuServlet</servlet-class >
11+ </servlet >
12+
13+ <servlet-mapping >
14+ <servlet-name >WorksWithHerokuServlet</servlet-name >
15+ <url-pattern >/</url-pattern >
16+ </servlet-mapping >
17+
18+ </web-app >
Original file line number Diff line number Diff line change 1+ package works .buddy .samples ;
2+
3+ import org .junit .Before ;
4+ import org .junit .Test ;
5+ import org .mockito .Mock ;
6+ import org .mockito .MockitoAnnotations ;
7+
8+ import javax .servlet .http .HttpServletRequest ;
9+ import javax .servlet .http .HttpServletResponse ;
10+ import java .io .ByteArrayOutputStream ;
11+ import java .io .PrintWriter ;
12+
13+ import static org .junit .Assert .assertEquals ;
14+ import static org .mockito .Mockito .when ;
15+
16+ public class WorksWithHerokuServletTest {
17+
18+ private WorksWithHerokuServlet servlet ;
19+
20+ @ Mock
21+ private HttpServletRequest request ;
22+
23+ @ Mock
24+ private HttpServletResponse response ;
25+
26+ @ Before
27+ public void setUp () throws Exception {
28+ MockitoAnnotations .initMocks (this );
29+ servlet = new WorksWithHerokuServlet ();
30+ }
31+
32+ @ Test
33+ public void testDoGet () throws Exception {
34+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
35+ PrintWriter writer = new PrintWriter (out );
36+ when (response .getWriter ()).thenReturn (writer );
37+
38+ servlet .doGet (request , response );
39+ assertEquals ("WEB APP WORKING" , new String ( out .toByteArray (), "UTF-8" ));
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments