PA165 Seminar Tools Filip Nguyen Lab Software Architectures and Information Systems Seminar 01 September 17, 2013 Today ● PA165 overview ● Computers/Laptops ● Netbeans IDE ● Glassfish, Tomcat ● Maven ● Playing with the source code ● Subversion PA165 Overview ● PA165 overview ● Maven ● Netbeans IDE ● Glassfish ● Subversion PA165 ● Topic ○ Spring, some Enterprise Java ○ Aimed to teach industry oriented technologies ● Team Projects ○ 4 members ○ developed throughout the course ● Organization ○ 1 main tutor ○ 2 tutors that help with projects ○ All the team members should be present when evaluating the projects Software you need ● Netbeans IDE 7.3.1 ● Maven 3.0.5 ● Java 1.7.x (Oracle JDK or OpenJDK) ● Subversion 1.7 or Git Using a Computer at B130 ● In each terminal you are using you must (use ~/.bashrc) ○ > module add netbeans-7.3.1-loc This ensures that your $JAVA_HOME variable and paths to Maven and Java are set correctly. ● If you want to use SVN you have to ○ > module add subversion-XXX (choose newest) ● You can check versions of your tools by running: ○ > netbeans & ○ > mvn --version FI - paths ● (1) Netbeans installation is on localhost at /usr/local/share/Modules/netbeans-7.3.1/ ● Your local (B130, nymfeXX) maven repository is located at /tmp/maven-repo-$LOGIN ● Glassfish server under (1) in glassfish-4.0 ● Tomcat located under (1) in apache-tomcat-7.0.34 Before starting Netbeans for the first time ● Delete ~/.netbeans dir ● Delete ~/personal_domain dir if it exists ● Start netbeans using > netbeans & Netbeans Adding Tomcat Server ● Start Netbeans ● Add Tomcat server to Servers section in Services tab ● Create some user (e.g. admin/admin) ● Do not forget to set Catalina base to a writable, empty and existing directory on localhost, e.g. /tmp/ Netbeans Adding Glasfish Server ● Start Netbeans ● Add Glassfish server to Servers section in Services tab ● Create the domain directory on your localhost. That means some subfolder of /tmp Netbeans Usage ● Always use /tmp directory for projects to ensure everything is run from localhost Demo app in Netbeans IDE ● currency-convertor is a simple example application you might be familiar with from PV168 Seminar in Java ● We will try to download, unpack, compile and deploy using different tools, modify it, etc. In Netbeans IDE ● Download currency-convertor.zip from IS MU /el/1433/podzim2013/PA165/um/cv/ ● Import clean currency-converter project to Netbeans ● Compile it In Maven ● Build projects, run tests, package projects (producing JAR files) ● Unzip it in and build it using terminal with maven > mvn compile > mvn test > mvn install > mvn clean Java 7 Features ● Download Java7Test.java and add it to your project IDE. Try out the unit tests in the file. ● Switching on Strings ● Diamond operator <> ● try-with-resource statement ● Multicatch Currency converter ● Compile the sources under Java 1.7 ○ reconfigure compile plugin: maven-compiler-plugin 3.0 1.7 1.7 Compile under Java 1.7 ● In CurrencyConverterTest ○ replace 2820.0 to 2_820.0 ○ (use an underscore to separate thousands) ● This will test that you really compile under Java 7 Mockito ● Utility library for testing ● Mock objects remember calling sequences ● Mocking: Verification of calling sequences ● Can be used only with annotations ● http://docs.mockito.googlecode.com/hg/latest/org/mockito/Mockito.html Using Mockito in CurrencyConvertorTest ● Add Mockito library dependency ○ http://mvnrepository.com ○ groupId: org.mockito, artifactId:mockito-all, version: 1.9.5 ● Use it to stub the ExchangeRateTable interface http://docs.mockito.googlecode.com/hg/latest/org/mockito/Mockito.html ● when....thenReturn ● doThrow...when... Subversion - a version control system ● Go through tutorial on kore: http://kore.fi.muni.cz/wiki/index.php/Subversion http://svnbook.red-bean.com/en/1.7/svn-book.html ● Subversion at this faculty: https://fadmin.fi.muni.cz/auth/sys/svn_ucty.mpl ● Create a repo ○ import currency converter there ○ make a change, commit ○ update ○ checkout Open Windows/Services Right Click Servers/Add Server Path to glassfish is /usr/local/share/Modules/netbeans- 7.3.1/glassfish-4.0/ The domain should be created to some random directory under /tmp After clicking finish, wait for this dialog to show up and click NO Createa a test web app: File/New Better to create it on local disk. But this may cause you to lose your project after you leave the PC Select Glassfish, Next In Services tab, right click Glassfish and Start it In Projects tab right click the application and hit Run You should see your webapp in a web browser