Skip to content

Commit

Permalink
NashTech-Labs#27 NashTech-Labs#14 Unit test cases were re-factored wi…
Browse files Browse the repository at this point in the history
…th respect to all code refactoring in controllers and repositories
  • Loading branch information
manishatGit committed Mar 31, 2015
1 parent 468aba9 commit 61cbdba
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 72 deletions.
6 changes: 3 additions & 3 deletions app/views/errorPage.scala.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@(message: String)
@main("Welcome to Play",user=None) {

<div >
<div class ="container">
<div class="page">
<h3>Page Not Found</h3>
<h1> 404: Page Not Found</h1>
<a class="navbar-brand" href="/">MCWS Home</a>
</div>
</div>
}
59 changes: 40 additions & 19 deletions app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=436035873185298";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id))
return;
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=436035873185298";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<!-- Wrap all page content here -->
<div id="wrap" class="margin">
Expand All @@ -43,35 +45,54 @@

<!-- Place this tag after the last share tag. -->
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/platform.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
(function() {
var po = document
.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/platform.js';
var s = document
.getElementsByTagName('script')[0];
s.parentNode
.insertBefore(
po,
s);
})();
</script>
<!-- Place this tag where you want the widget to render. -->
<div class="g-follow" data-annotation="bubble" data-height="24" data-href="//plus.google.com/101596762455378096324" data-rel="publisher">
</div>

<!-- Place this tag after the last widget tag. -->
<script type="text/javascript">
(function() {
(function() {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
})();
</script>
<script src="//platform.linkedin.com/in.js" type="text/javascript">
lang: en_US
</script>
lang: en_US
</script>
<script type="IN/Share" data-url="http://www.mycellwasstolen.com/" data-counter="right">
</script>
<span class="fb-like" data-href="https://www.facebook.com/mycellwasstolen.mcws" data-width="200" data-show-faces="false" data-send="true"></span>
<a href="https://twitter.com/mycellwasstolen" class="twitter-follow-button" data-show-count="true" data-size="large">Follow @{"@MCWS"}</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<script>
!function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/
.test(d.location) ? 'http' : 'https';
if (!d.getElementById(id)) {
js = d.createElement(s);
js.id = id;
js.src = p + '://platform.twitter.com/widgets.js';
fjs.parentNode.insertBefore(js, fjs);
}
}(document, 'script', 'twitter-wjs');
</script>
</div>
}

Expand Down
6 changes: 3 additions & 3 deletions test/Router/RouterTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import model.repository.AuditRepository
class RouterTest extends Specification {

val date = new java.sql.Date(new java.util.Date().getTime())
val brand = Brand("nokia", "12-17-2013")
val brand = Brand("nokia")
val model = Model("E5", 1)
val mobileUser = Mobile(
"sushil", 1, 1, "864465028854206", "864465028854206", "12-05-2013", "+91 8375919908",
"[email protected]", "stolen", Status.pending, "test", "12-17-2013", "sushil.png", "nokia", "E5")
"sushil", 1, 1, "864465028854206", "864465028854206", new java.sql.Date(new java.util.Date().getTime()), "+91 8375919908",
"[email protected]", "stolen", Status.pending, "test", new java.sql.Date(new java.util.Date().getTime()), "sushil.png", "nokia", "E5")

"respond to the index Action" in {
running(FakeApplication()) {
Expand Down
27 changes: 15 additions & 12 deletions test/controllers/AdminControllerTestCases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,39 @@ import play.api.Play.current
import play.api.cache.Cache
import play.api.test.FakeApplication
import play.api.test.Helpers._
import utils.Common
import utils.StatusUtil.Status
import play.api.test.FakeRequest
import play.api.mvc.Security
import java.util.Date
import utils.S3UtilComponent
import utils.MailUtil
import java.util.Calendar

class AdminControllerTestCases extends Specification with Mockito {

val stolenMobileUser = Mobile(
"sushil", 1, 1, "864465028854206", "123456789012677", "12-05-2013", "+91 9839839830",
"[email protected]", "stolen", Status.pending, "test", "12-17-2013", "gaurav.png", "nokia", "E5")
"sushil", 1, 1, "864465028854206", "123456789012677", new java.sql.Date(new java.util.Date().getTime()), "+91 9839839830",
"[email protected]", "stolen", Status.pending, "test", new java.sql.Date(new java.util.Date().getTime()), "gaurav.png", "nokia", "E5")

val stolenMobileUser1 = Mobile(
"sushil", 1, 1, "864465028854206", "123456789012677", "12-05-2013", "+91 9839839830",
"[email protected]", "Clean", Status.pending, "test", "12-17-2013", "gaurav.png", "nokia", "E5")
"sushil", 1, 1, "864465028854206", "123456789012677", new java.sql.Date(new java.util.Date().getTime()), "+91 9839839830",
"[email protected]", "Clean", Status.pending, "test", new java.sql.Date(new java.util.Date().getTime()), "gaurav.png", "nokia", "E5")

val cleanMobileUser = Mobile(
"sushil", 1, 1, "12345678901234", "123456789012678", "12-05-2013", "+91 9839839830",
"[email protected]", "Clean", Status.pending, "test", "12-17-2013", "gaurav.png", "nokia", "E5")
"sushil", 1, 1, "12345678901234", "123456789012678", new java.sql.Date(new java.util.Date().getTime()), "+91 9839839830",
"[email protected]", "Clean", Status.pending, "test", new java.sql.Date(new java.util.Date().getTime()), "gaurav.png", "nokia", "E5")

val mobileWithBrand = (Mobile(
"gs", 1, 1, "864465028854206", "123456789012677", "12-05-2013", "+91 9839839830",
"[email protected]", "stolen", Status.pending, "test", "12-17-2013", "gaurav.png", "nokia", "E5"), "nokia", "E5")
"gs", 1, 1, "864465028854206", "123456789012677", new java.sql.Date(new java.util.Date().getTime()), "+91 9839839830",
"[email protected]", "stolen", Status.pending, "test", new java.sql.Date(new java.util.Date().getTime()), "gaurav.png", "nokia", "E5"), "nokia", "E5")

val getAllMobilesWithBrand: List[(Mobile, String, String)] = List(mobileWithBrand)
val audit = List(Audit("864465028854206", "12-05-2013", Some(1)))
val calender = Calendar.getInstance
val now:java.util.Date = calender.getTime
val timeStamp = new java.sql.Timestamp(now.getTime())
val audit = List(Audit("864465028854206", timeStamp , Some(1)))
val user = User("admin", "knol2013")

val mockedMail = mock[Common]
val mockedMail = mock[MailUtil]
val mockedS3Util = mock[S3UtilComponent]
val mockedMobilRepo = mock[MobileRepository]
val mockedAuditRepo = mock[AuditRepository]
Expand Down
22 changes: 14 additions & 8 deletions test/controllers/MobileControllerTestCases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import play.api.test.FakeRequest
import play.api.test.Helpers._
import model.repository._
import utils.StatusUtil.Status
import utils.Common
import utils.S3UtilComponent
import play.api.mvc.Request
import play.api.mvc.MultipartFormData
Expand All @@ -23,11 +22,14 @@ import play.api.mvc.MultipartFormData.BadPart
import play.api.mvc.MultipartFormData.MissingFilePart
import play.api.test.FakeHeaders
import play.mvc.Result
import utils.MailUtil
import java.util.Calendar
import utils.CommonUtils

class MobileControllerTestCases extends Specification with Mockito {

val date = new java.sql.Date(new java.util.Date().getTime())
val newbrand = Brand("nokia", "12-17-2013", Some(1))
val newbrand = Brand("nokia", Some(1))
val brand = List(newbrand)
val brandById: Option[Brand] = Some(newbrand)
val newmodel = Model("N72", 1)
Expand All @@ -37,18 +39,22 @@ class MobileControllerTestCases extends Specification with Mockito {
val username = "admin"

val mobileUser = Mobile(
"sushil", 1, 1, "864465028854206", "864465028854206", "12-03-2013", "+91 8375919908",
"[email protected]", "stolen", Status.pending, "test", "12-17-2015", "ss.png", "nokia", "E5")
"sushil", 1, 1, "864465028854206", "864465028854206", new java.sql.Date(new java.util.Date().getTime()), "+91 8375919908",
"[email protected]", "stolen", Status.pending, "test", new java.sql.Date(new java.util.Date().getTime()), "ss.png", "nokia", "E5")

val timestamp = new Audit("864465028854206", "12-17-2015", Some(1))
val calender = Calendar.getInstance
val now: java.util.Date = calender.getTime
val timeStamp = new java.sql.Timestamp(now.getTime())
val timestamp = new Audit("864465028854206", timeStamp, Some(1))

val mockedMail = mock[Common]
val mockedMail = mock[MailUtil]
val s3util = mock[S3UtilComponent]
val mockedMobileRepo = mock[MobileRepository]
val mockedBrandRepo = mock[BrandRepository]
val mockedModelRepo = mock[ModelRepository]
val mockedAuditRepo = mock[AuditRepository]
val mobileController = new MobileController(mockedMobileRepo, mockedBrandRepo, mockedModelRepo, mockedAuditRepo, mockedMail, s3util)
val mockedCommonUtils = mock[CommonUtils]
val mobileController = new MobileController(mockedMobileRepo, mockedBrandRepo, mockedModelRepo, mockedAuditRepo, mockedMail, s3util,mockedCommonUtils)

"MobileControllerTesting: mobileRegistrationForm" in {
running(FakeApplication()) {
Expand Down Expand Up @@ -98,7 +104,7 @@ class MobileControllerTestCases extends Specification with Mockito {
"mobileModelId" -> Seq("1"),
"imeiMeid" -> Seq("123456789012347"),
"otherImeiMeid" -> Seq("1234"),
"purchaseDate" -> Seq("12-12-2012"),
"purchaseDate" -> Seq("2012-12-12"),
"contactNo" -> Seq("9958324567"),
"email" -> Seq("[email protected]"),
"regType" -> Seq("pending"),
Expand Down
12 changes: 8 additions & 4 deletions test/repository/RepositoryTest/AuditRepoTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import model.repository.Audit
import play.api.test.FakeApplication
import play.api.test.Helpers._
import model.repository.AuditRepository
import java.util.Calendar

class AuditRepoTest extends FunSuite {
val calender = Calendar.getInstance
val now: java.util.Date = calender.getTime
val timeStamp = new java.sql.Timestamp(now.getTime())

val auditTimestamp = Audit("123456789012345", "25/03/15 23:50", Some(1))
val auditTimestamp = Audit("123456789012345", timeStamp, Some(1))

//Tests insertion of a timeStamp
test("AuditRepository: insert an Audit Record with Imeid and timestamp") {
Expand All @@ -27,14 +31,14 @@ class AuditRepoTest extends FunSuite {
assert(returnedValue === List(auditTimestamp))
}
}

//Test listing of all TimeStamps
test("AuditRepository: list all timestamps") {
test("AuditRepository: list all timestamps") {
running(FakeApplication()) {
AuditRepository.insertTimestamp(auditTimestamp)
AuditRepository.insertTimestamp(auditTimestamp)
val returnedValue = AuditRepository.getAllTimestamps
assert(returnedValue === List(auditTimestamp,Audit("123456789012345", "25/03/15 23:50", Some(2))))
assert(returnedValue === List(auditTimestamp, Audit("123456789012345", timeStamp, Some(2))))
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/repository/RepositoryTest/BrandRepoTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.scalatest.BeforeAndAfterAll

class BrandRepoTest extends FunSuite {

val brand = Brand("nokia", "12-17-2013",Some(1))
val brand = Brand("nokia",Some(1))

//Tests Brand Insertion
test("BrandRepository: insert a brand successfully") {
Expand Down
Loading

0 comments on commit 61cbdba

Please sign in to comment.