Skip to content

Commit

Permalink
#39 refactoring, validator skelton
Browse files Browse the repository at this point in the history
  • Loading branch information
stormcat24 committed Feb 21, 2015
1 parent 3b2b1d2 commit 4b4b183
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import jp.co.cyberagent.aeromock.cli.Job
object CliJobs {

val jobs = Seq(
classOf[ViewCheckJob]
classOf[ValidationJob]
)

lazy val availableJobs = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package jp.co.cyberagent.aeromock.cli.job

import java.nio.file.Files

import jp.co.cyberagent.aeromock.AeromockBadUsingException
import jp.co.cyberagent.aeromock.cli.option.JobOperation
import jp.co.cyberagent.aeromock.cli.validation.TemplateValidator
import jp.co.cyberagent.aeromock.cli.{CliJob, Job}
import jp.co.cyberagent.aeromock.config.Project
import jp.co.cyberagent.aeromock.template.TemplateService
import scaldi.Injector

import scala.reflect.io.Directory
import scalaz._
import Scalaz._

/**
* Job to check templates and data.
* @author stormcat24
* @param command [[jp.co.cyberagent.aeromock.cli.option.JobOperation]]
*/
@Job(name = "test", description = "Execute view test.")
class ValidationJob(override val command: JobOperation)(implicit inj: Injector) extends CliJob {

val project = inject[Project]

// templateとデータのセット
val reportRoot = project._test.reportRoot

// prepare directory
val dir = Directory.apply(scala.reflect.io.Path.apply(reportRoot.toFile))
dir.deleteRecursively()
Files.createDirectories(reportRoot)


/**
* @inheritdoc
*/
override def execute(): Int = {

(project.template, project.data) match {
case (Success(Some(template)), Success(Some(data))) => // OK
// templateとdataを操作してリクエストをつくる
new TemplateValidator().validate(template, data)
// テンプレをループ
// 紐づくデータを探す。あればリクエスト、なければ警告
case (Success(_), Success(_)) => // nothing to do
case (_, _) => // TODO error
}

project.ajax match {
case Success(Some(ajax)) =>
case Success(_) => // nothing to do
case f @ Failure(_) => // TODO error
}

project.messagepack match {
case Success(Some(messagepack)) =>
case Success(_) => // nothing to do
case f @ Failure(_) => // TODO error
}

(project.protobuf, project.data) match {
case (Success(Some(protobuf)), Success(Some(data))) => // OK
case (Success(_), Success(_)) => // nothing to do
case (_, _) => // TODO error
}

// TODO テスト設定
// TODO useragent
0
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package jp.co.cyberagent.aeromock.cli.validation

import jp.co.cyberagent.aeromock.config.{Data, Template}
import jp.co.cyberagent.aeromock.helper._
import jp.co.cyberagent.aeromock.template.TemplateService
import scaldi.{Injector, Injectable}

/**
*
* @author stormcat24
*/
class TemplateValidator(implicit inj: Injector) extends AnyRef with Injectable {

def validate(template: Template, data: Data): Unit = {

// TODO 拡張子取るためだけに取るのイケてない
val templateService = inject[Option[TemplateService]].get

template.contexts.map { context =>
val contextRoot = s"http://${context.domain}:${context.port}"

// TODO 拡張子フィルタリング
context.root.filterChildren(s".${templateService.extension}$$").map { templatePath =>
println(templatePath)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package jp.co.cyberagent.aeromock.cli
import java.nio.file.Path

import jp.co.cyberagent.aeromock.AeromockTestModule
import jp.co.cyberagent.aeromock.cli.job.ViewCheckJob
import jp.co.cyberagent.aeromock.cli.job.ValidationJob
import jp.co.cyberagent.aeromock.cli.option.CliCommand
import jp.co.cyberagent.aeromock.config.definition.ProjectDef
import jp.co.cyberagent.aeromock.test.SpecSupport
Expand All @@ -24,6 +24,6 @@ class CliJobSelectorSpec extends Specification with Tables with SpecSupport {
val command = CliCommand(Array("test"))

val selector = inject[CliJobSelector]
selector.select(command).getClass must_== classOf[ViewCheckJob]
selector.select(command).getClass must_== classOf[ValidationJob]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ case class Project(
}
}

def hasError(): Unit = {

}

def templateScript: Path = root / "template.script"
def dataScript: Path = root / "data.groovy"
def ajaxScript: Path = root / "ajax.groovy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import java.nio.file.Path

import jp.co.cyberagent.aeromock.config
import jp.co.cyberagent.aeromock.config._
import jp.co.cyberagent.aeromock.template.TemplateContexts._
import jp.co.cyberagent.aeromock.template.TemplateService
import org.apache.commons.lang3.StringUtils
import scaldi.{Injectable, Injector}
Expand Down Expand Up @@ -177,13 +176,16 @@ class TemplateDef extends AnyRef with Injectable {

}
case Failure(value) => {
// navigatorがtemplate.rootの値に依存するので
List[TemplateContext]().successNel[String]
}
}

(rootResult |@| serviceClassResult |@| contextsResult) {
Template(_, _, _).some
(rootResult |@| serviceClassResult |@| contextsResult) { (r, s, c) =>
if (c.isEmpty) {
Template(r, s, List(TemplateContext("localhost", inject[Int] (identified by 'listenPort), r))).some
} else {
Template(r, s, c).some
}
}
}

Expand Down

This file was deleted.

0 comments on commit 4b4b183

Please sign in to comment.