本文整理汇总了Scala中org.junit.Before类的典型用法代码示例。如果您正苦于以下问题:Scala Before类的具体用法?Scala Before怎么用?Scala Before使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Before类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: SettingsTest
//设置package包名称以及导入依赖的类
package org.eck.entities
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig
import com.google.appengine.tools.development.testing.LocalServiceTestHelper
import com.google.gson.JsonObject
import org.junit.{Assert, Test, After, Before}
class SettingsTest {
val helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig())
@Before def setUp(): Unit = helper.setUp
@After def tearDown() = helper.tearDown()
@Test
def testSetAndGetSetting = {
Settings.set("bla", "ble")
Assert.assertTrue(Settings.get("bla").isDefined)
Assert.assertEquals("ble", Settings.get("bla").get)
}
@Test
def testFromJson = {
val json = new JsonObject
json.addProperty("bla", "ble")
json.addProperty("ble", "bla")
Settings.fromJson(json)
Assert.assertTrue(Settings.get("bla").isDefined)
Assert.assertEquals("ble", Settings.get("bla").get)
Assert.assertTrue(Settings.get("ble").isDefined)
Assert.assertEquals("bla", Settings.get("ble").get)
}
@Test
def asJson = {
Settings.set("bla", "ble")
Settings.set("ble", "bla")
val json = Settings.asJson
Assert.assertEquals("ble", json.get("bla").getAsString)
Assert.assertEquals("bla", json.get("ble").getAsString)
}
}
开发者ID:erickzanardo,项目名称:spammer,代码行数:47,代码来源:SettingsTest.scala
示例2: TestProducer
//设置package包名称以及导入依赖的类
package com.rockiey.kafka
import java.util.{Date, Properties, Random}
import kafka.producer.{KeyedMessage, Producer, ProducerConfig}
import org.junit.{After, Before, Test}
class TestProducer {
val brokers = "localhost:9092"
val topic = "test"
val rnd = new Random()
val props = new Properties()
props.put("metadata.broker.list", brokers)
props.put("serializer.class", "kafka.serializer.StringEncoder")
//props.put("partitioner.class", "com.colobu.kafka.SimplePartitioner")
props.put("producer.type", "async")
//props.put("request.required.acks", "1")
var producer: Producer[String, String] = null
@Before
def before: Unit = {
val config = new ProducerConfig(props)
producer = new Producer[String, String](config)
}
@After
def after: Unit = {
producer.close()
}
def produce(events: Int): Unit = {
val t = System.currentTimeMillis()
for (nEvents <- Range(0, events)) {
val runtime = new Date().getTime()
val ip = "192.168.2." + rnd.nextInt(255)
val msg = runtime + "," + nEvents + ",www.example.com," + ip
val data = new KeyedMessage[String, String](topic, ip, msg)
producer.send(data)
}
System.out.println("sent per second: " + events * 1000 / (System.currentTimeMillis() - t))
}
@Test
def testProducer: Unit = {
produce(100)
}
@Test
def testConsumer {
}
}
开发者ID:rockie-yang,项目名称:explore-spark-kafka,代码行数:58,代码来源:TestProducer.scala
示例3: DocumentTest
//设置package包名称以及导入依赖的类
package ch.epfl.callgraph.visualization
import ch.epfl.callgraph.utils.Utils.CallGraph
import ch.epfl.callgraph.visualization.view.{D3GraphView, HtmlView}
import org.junit.Assert._
import org.junit.{Before, Test}
import org.scalajs.dom.html._
import org.scalajs.{dom => sdom}
import upickle.{default => upickle}
import scala.scalajs
import scala.scalajs.js
import scala.scalajs.js.Dynamic.global
class DocumentTest {
val $ = global.jQuery
@Before
def setupDocument() : Unit = {
$("body").html("")
$("body")
.append(
global.jQuery("<div id=\"header\"><h1>Scala.js Call Graph Visualization</h1></div>" +
"<div id=\"nav\" style=\"overflow:auto\"></div>" +
"<div id=\"main\" style=\"overflow:auto\"></div>"))
HtmlView.main() // setup the file upload button
D3GraphView.setCallGraph(upickle.read[CallGraph](generateGraph))
HtmlView.updateHtmlAfterLoad(sdom.document.getElementById("nav").asInstanceOf[Div])
D3GraphView.renderGraph()
}
def generateGraph = {
"""{"classes":[{"encodedName":"s_Predef$Triple$2","displayName":"scala.Predef$Triple$2","isExported":true,"superClass":[],"interfaces":[],"methods":[]}]}"""
}
@Test def testInitialDOM(): Unit = {
assertEquals(1, $("#header").length)
assertEquals(1, $("#nav").length)
assertEquals(1, $("#main").length)
}
@Test def testInitialLayer : Unit = {
HtmlView.showLayers
assertEquals(1, $("li > a.active").length)
}
@Test def testSvgSingleNode : Unit = {
println($("svg").html())
$("svg").find("circle").each({(li: Html) => {
println($(li).attr("class"))
// $(li).contextmenu()
}}: scalajs.js.ThisFunction)
assertEquals(1, $("svg").find("circle").length)
}
}
开发者ID:lionelfleury,项目名称:scala-js-call-graph,代码行数:60,代码来源:DocumentTest.scala
示例4: ExampleIntegrationTest
//设置package包名称以及导入依赖的类
package scaps.eclipse
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.jdt.core.IPackageFragmentRoot
import org.eclipse.jdt.core.JavaCore
import org.eclipse.jdt.internal.core.PackageFragment
import org.junit.Before
import org.junit.Test
import org.junit.Ignore
import org.scalaide.core.testsetup.TestProjectSetup
class ExampleIntegrationTest extends TestProjectSetup("simple-structure-builder") {
@Before
def setup {
println("iuu setup test")
}
@Test
@Ignore
def test1 {
val javaProj = project.javaProject
val srcDirs = javaProj.getAllPackageFragmentRoots.filter(_.getKind == IPackageFragmentRoot.K_SOURCE).head.getChildren.last
val p: PackageFragment = srcDirs.asInstanceOf[PackageFragment]
val srcs = p.getCompilationUnits.head.getResource
println("done")
}
}
开发者ID:scala-search,项目名称:scala-ide-scaps,代码行数:33,代码来源:ExampleIntegrationTest.scala
示例5: MessageTest
//设置package包名称以及导入依赖的类
package org.eck.entities
import com.google.appengine.tools.development.testing.{LocalDatastoreServiceTestConfig, LocalServiceTestHelper}
import org.junit.{Assert, After, Before, Test}
class MessageTest {
val helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig().setDefaultHighRepJobPolicyUnappliedJobPercentage(100))
@Before def setUp(): Unit = helper.setUp
@After def tearDown() = helper.tearDown()
@Test
def testSaveAndFind = {
val id = new Message("messageTitle", "messageContent").save
val message = Message.findById(id)
Assert.assertEquals(id, message.id)
Assert.assertEquals("messageTitle", message.title)
Assert.assertEquals("messageContent", message.content)
}
}
开发者ID:erickzanardo,项目名称:spammer,代码行数:22,代码来源:MessageTest.scala
示例6: AbstractScopTest
//设置package包名称以及导入依赖的类
package polyite.schedule
import java.util.Properties
import polyite.config.Config
import org.junit.Before
import polyite.ScopInfo
import polyite.export.JSCOPInterface
import java.util.logging.Logger
import polyite.AbstractTest
import isl.Isl
object AbstractScopTest {
private def checkIsValidSched(deps : Set[Dependence], sched : isl.UnionMap) {
val schedDims : List[isl.UnionMap] = Isl.splitMultiDimUnionMap(sched)
val uncarriedDeps : Set[Dependence] = schedDims.zipWithIndex.foldLeft(deps)((remDeps : Set[Dependence], dimSched : (isl.UnionMap, Int)) => {
remDeps.view.foreach((dep : Dependence) => {
assert(!ScheduleUtils.getDirectionOfDep(dimSched._1, dep).isNegative, f"dependence ${dep} is violated by dimension ${dimSched._2}")
})
remDeps -- ScheduleUtils.getDepsCarriedBySchedule(dimSched._1, remDeps)
})
assert(uncarriedDeps.isEmpty, f"There are uncarried dependences:\n${uncarriedDeps.mkString("\n")}")
}
}
abstract class AbstractScopTest extends AbstractTest {
protected val myLogger = Logger.getLogger("")
protected var scop : ScopInfo = null
protected var deps : Set[Dependence] = null
protected var domInfo : DomainCoeffInfo = null
protected var conf : Config = null
protected var scopStr : String = null
@Before
def prepare() {
scop = JSCOPInterface.parseJSCOP(scopStr) match {
case None => throw new RuntimeException()
case Some(s) => s
}
val t : (Set[Dependence], DomainCoeffInfo) = ScheduleSpaceUtils.calcDepsAndDomInfo(scop)
deps = t._1
domInfo = t._2
conf = createTestConfig() match {
case None => throw new RuntimeException()
case Some(c) => c
}
runFurtherPreparation()
}
def runFurtherPreparation()
}
开发者ID:stganser,项目名称:polyite,代码行数:56,代码来源:AbstractScopTest.scala
示例7: VideoTranscoderTest
//设置package包名称以及导入依赖的类
package com.waz
import java.io.File
import java.util.concurrent.CountDownLatch
import android.content.Context
import android.net.Uri
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import com.waz.api.AssetFactory.LoadCallback
import com.waz.api.{AssetFactory, AssetForUpload}
import com.waz.bitmap.video.VideoTranscoder
import com.waz.service.ZMessaging
import com.waz.threading.Threading
import org.junit.runner.RunWith
import org.junit.{Assert, Before, Test}
import scala.concurrent.Await
import scala.concurrent.duration._
@RunWith(classOf[AndroidJUnit4])
class VideoTranscoderTest {
@Before def setUp(): Unit = {
Threading.AssertsEnabled = false
ZMessaging.onCreate(context)
}
@Test def audioTranscodingFrom8kHz(): Unit = {
val transcoder = VideoTranscoder(context)
val out = File.createTempFile("video", ".mp4", context.getCacheDir)
val future = transcoder(Uri.parse("content://com.waz.test/8khz.mp4"), out, { _ => })
Assert.assertEquals(out, Await.result(future, 15.seconds))
}
@Test def assetLoadingWithNoAudio(): Unit = {
val latch = new CountDownLatch(1)
var asset = Option.empty[AssetForUpload]
AssetFactory.videoAsset(Uri.parse("content://com.waz.test/no_audio.mp4"), new LoadCallback {
override def onLoaded(a: AssetForUpload): Unit = {
asset = Some(a)
latch.countDown()
}
override def onFailed(): Unit = {
println(s"transcode failed")
latch.countDown()
}
})
latch.await()
Assert.assertTrue(asset.isDefined)
}
def context: Context = instr.getTargetContext
def instr = InstrumentationRegistry.getInstrumentation
}
开发者ID:wireapp,项目名称:wire-android-sync-engine,代码行数:61,代码来源:VideoTranscoderTest.scala
示例8: AssetMetaDataTest
//设置package包名称以及导入依赖的类
package com.waz
import android.content.Context
import android.net.Uri
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import com.waz.model.AssetMetaData
import com.waz.service.ZMessaging
import com.waz.threading.Threading
import com.waz.utils._
import org.junit.runner.RunWith
import org.junit.{Assert, Before, Test}
import scala.concurrent.Await
import scala.concurrent.duration._
@RunWith(classOf[AndroidJUnit4])
class AssetMetaDataTest {
@Before def setUp(): Unit = {
Threading.AssertsEnabled = false
ZMessaging.onCreate(context)
}
@Test def testAudioDurationLoadingFromUri(): Unit = {
val meta = Await.result(AssetMetaData.Audio(context, Uri.parse("content://com.waz.test/32kbps.m4a")), 5.seconds)
Assert.assertEquals(309L, meta.fold2(0L, _.duration.getSeconds))
}
def context: Context = instr.getTargetContext
def instr = InstrumentationRegistry.getInstrumentation
}
开发者ID:wireapp,项目名称:wire-android-sync-engine,代码行数:34,代码来源:AssetMetaDataTest.scala
示例9: ScheduleTest
//设置package包名称以及导入依赖的类
package com.gaiam.gcsis.util
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.Assert._
import org.joda.time.{Interval => JInterval}
import org.joda.time.Instant
import org.joda.time.DateTime
class ScheduleTest {
val i1 : JInterval = new JInterval(new DateTime("2010-01-01"), new DateTime("2010-02-01"))
val i2 : JInterval = new JInterval(new DateTime("2010-02-01"), new DateTime("2010-03-01"))
val i3 : JInterval = new JInterval(new DateTime("2010-03-01"), new DateTime("2010-04-01"))
val i4 : JInterval = new JInterval(new DateTime("2010-01-15"), new DateTime("2010-03-15"))
@Before
def setUp: Unit = {
}
@After
def tearDown: Unit = {
}
@Test
def testOneIntervalContinuousInterval = {
val schedule = new IntervalSchedule(Array(i1))
val begin = new DateTime("2010-01-01")
val interval = schedule.continuousInterval(begin)
assertTrue(interval.isDefined)
assertEquals(begin, interval.get.getStart)
assertEquals(i1.getEnd, interval.get.getEnd)
}
@Test
def testTwoOverlappingIntervalContinuousInterval = {
val schedule = new IntervalSchedule(Array(i1, i4))
val date = new DateTime("2010-01-20")
val interval = schedule.continuousInterval(date)
assertTrue(interval.isDefined)
assertTrue("interval '" + interval + "' doesn't contain date '" + date + "'", interval.get.contains(date))
assertEquals(i4.getEnd, interval.get.getEnd)
}
@Test
def testAbutsIntervalContinuousInterval = {
val schedule = new IntervalSchedule(Array(i1, i2, i3))
val date = new DateTime("2010-01-20")
val interval = schedule.continuousInterval(date)
assertTrue(interval.isDefined)
assertTrue(interval.get.contains(date))
assertEquals(i3.getEnd, interval.get.getEnd)
}
}
开发者ID:GaiamTV,项目名称:gcsi-scala-util,代码行数:62,代码来源:IntervalScheduleTest.scala
示例10: LocalSparkRunner
//设置package包名称以及导入依赖的类
import com.ixeption.spark.dota2.util.Dota2Analytics
import org.apache.spark.SparkConf
import org.apache.spark.sql._
import org.apache.spark.sql.functions._
import org.junit.{Before, Test}
@Test
object LocalSparkRunner {
@Before
def prepare(): Unit = {
System.setProperty("hadoop.home.dir", "C:\\Users\\Christian\\Dev\\hadoop-2.6.0")
}
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("Dota2")
conf.set("spark.master", "local[4]")
conf.set("spark.sql.warehouse.dir", "file:///C:/Users/Christian/AppData/Local/Temp/spark-warehouse")
//conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
//conf.set("spark.kryoserializer.buffer.max", "512m")
val spark: SparkSession = SparkSession.builder().appName("Dota2").config(conf).getOrCreate()
val dataFrame: DataFrame = spark.read.json("src/main/resources/data/matches.json")
//val dataFrame: DataFrame = spark.read.parquet("matchespar")
import dataFrame.sqlContext.implicits._
val items: DataFrame = spark.read.json("src/main/resources/data/items_23_06_2016.json")
.select(explode($"result.items"))
.toDF()
broadcast(items)
val heros: DataFrame = spark.read.json("src/main/resources/data/heros_01_07_2016.json")
.select(explode($"result.heroes"))
.toDF()
broadcast(heros)
val matchesDf = dataFrame.select(explode($"matches")).toDF()
Dota2Analytics.run(spark, matchesDf, heros, items)
spark.stop()
}
}
开发者ID:digital-thinking,项目名称:dota2-analytics,代码行数:44,代码来源:LocalSparkRunner.scala
示例11: AbstractRealmTestCase
//设置package包名称以及导入依赖的类
import android.content.Context
import android.support.test.InstrumentationRegistry
import android.test.RenamingDelegatingContext
import com.github.aafa.model.User
import io.realm.RealmConfiguration.Builder
import io.realm.{Realm, RealmConfiguration}
import org.junit.Before
abstract class AbstractRealmTestCase {
var mMockContext: Context = null
lazy val realmConfiguration: RealmConfiguration = new Builder(mMockContext).deleteRealmIfMigrationNeeded().build()
lazy val realm: Realm = Realm.getInstance(realmConfiguration)
@Before
def setup() = {
mMockContext = new RenamingDelegatingContext(InstrumentationRegistry.getInstrumentation.getTargetContext, "test_")
clearData
}
def clearData: Unit = {
realmTransaction(_.clear(classOf[User]))
}
def realmTransaction(action: Realm => Unit) = {
realm.beginTransaction()
action(realm)
realm.commitTransaction()
}
}
开发者ID:aafa,项目名称:realm-sbt-plugin,代码行数:32,代码来源:AbstractRealmTestCase.scala
示例12: MowerFactoryImplTest
//设置package包名称以及导入依赖的类
package com.xebia.mowitnow.model.factory
import com.xebia.mowitnow.model.Entity.{Orientation, Mower, Position}
import com.xebia.mowitnow.model.Factory.MowerFactoryImpl
import org.junit.Assert._
import org.junit.{Test, Before}
import org.scalatest.Assertions
class MowerFactoryImplTest extends Assertions {
var mowerFactory: MowerFactoryImpl = null
@Before def initialize() {
mowerFactory = new MowerFactoryImpl
}
@Test def testCreateMower() {
// Create mower with position 1,5 & orientation N
assertEquals(Some(Mower(Position(1,5, Orientation.N))), mowerFactory.createMower("1 5 N"))
//Try to create mower with unsupported orientation
assertEquals(None, mowerFactory.createMower("1 5 A"))
}
}
开发者ID:MOKEDDEM,项目名称:mow-itnow,代码行数:25,代码来源:MowerFactoryImplTest.scala
示例13: GroundFactoryImplTest
//设置package包名称以及导入依赖的类
package com.xebia.mowitnow.model.factory
import com.xebia.mowitnow.model.Entity.{Dimension, Ground}
import com.xebia.mowitnow.model.Factory.GroundFactoryImpl
import org.junit.Assert._
import org.junit.{Test, Before}
import org.scalatest.Assertions
class GroundFactoryImplTest extends Assertions {
var groundFactory: GroundFactoryImpl = null
@Before def initialize() {
groundFactory = new GroundFactoryImpl
}
@Test def testCreateGround() {
assertEquals(Some(Ground(Dimension(5, 5))), groundFactory.createGround("5 5"))
assertEquals(Some(Ground(Dimension(5, 5))), groundFactory.createGround(" 5 5 "))
// Handling of unsupported format of ground
assertEquals(None, groundFactory.createGround("A 5"))
assertEquals(None, groundFactory.createGround(""))
assertEquals(None, groundFactory.createGround("5.5 5"))
assertEquals(None, groundFactory.createGround("-1 5"))
}
}
开发者ID:MOKEDDEM,项目名称:mow-itnow,代码行数:29,代码来源:GroundFactoryImplTest.scala
示例14: InstructionFactoryImplTest
//设置package包名称以及导入依赖的类
package com.xebia.mowitnow.model.factory
import com.xebia.mowitnow.model.Entity.{Instruction, Dimension, Ground}
import com.xebia.mowitnow.model.Factory.InstructionFactoryImpl
import org.junit.Assert._
import org.junit.{Test, Before}
import org.scalatest.Assertions
class InstructionFactoryImplTest extends Assertions {
var instructionFactory: InstructionFactoryImpl = null
@Before def initialize() {
instructionFactory = new InstructionFactoryImpl
}
@Test def testCreateInstruction() {
// Create a list of instruction with some unsupported instructions
assertEquals(Some(List(Instruction.A, Instruction.A, Instruction.G, Instruction.A, Instruction.A, Instruction.D, Instruction.G, Instruction.A, Instruction.A)), instructionFactory.createInstruction("AAGEAADGAA"))
// Create list of instruction from only unsupported instructions
assertEquals(None, instructionFactory.createInstruction("IEH"))
}
}
开发者ID:MOKEDDEM,项目名称:mow-itnow,代码行数:25,代码来源:InstructionFactoryImplTest.scala
示例15: GroundServiceImplTest
//设置package包名称以及导入依赖的类
package com.xebia.mowitnow.service
import com.xebia.mowitnow.model.Entity.{Orientation, Position, Dimension, Ground}
import com.xebia.mowitnow.model.Factory.GroundFactoryImpl
import org.junit.Assert._
import org.junit.{Test, Before}
import org.scalatest.Assertions
class GroundServiceImplTest extends Assertions {
implicit var groundFactory: GroundFactoryImpl = null
var groundService: GroundServiceImpl = null
@Before def initialize() {
groundFactory = new GroundFactoryImpl
groundService = new GroundServiceImpl
}
@Test def testIsInsideGround() {
val ground = Ground(Dimension(5,5))
assertEquals(true, groundService.isInsideGround(ground,Position(1,5,Orientation.N)))
assertEquals(false, groundService.isInsideGround(ground,Position(-1,5,Orientation.N)))
assertEquals(false, groundService.isInsideGround(ground,Position(5,6,Orientation.N)))
assertEquals(false, groundService.isInsideGround(ground,Position(6,5,Orientation.N)))
}
}
开发者ID:MOKEDDEM,项目名称:mow-itnow,代码行数:27,代码来源:GroundServiceImplTest.scala
示例16: PluginTest
//设置package包名称以及导入依赖的类
package org.webant.plugin.test
import java.nio.charset.Charset
import org.apache.http.client.fluent.Response
import org.junit.{After, Before, Test}
import org.scalatest.junit.AssertionsForJUnit
class PluginTest extends AssertionsForJUnit {
@Before
def init(): Unit = {
}
@After
def exit() {
}
@Test
def testRegex(): Unit = {
val regex = "http://user.mahua.com/ajax/joke/checkJokesDynamic[\\w\\W]*"
val url = "http://user.mahua.com/ajax/joke/checkJokesDynamic?callback=jQuery17209865076656443552_1498566208473&joke_ids=1679937%2C1679936%2C1679935%2C1679934%2C1679933%2C1679932%2C1679928%2C1679927%2C1679929%2C1679931%2C1679930%2C1679926%2C1679923%2C1679921%2C1679919%2C1679918%2C1679925%2C1679924%2C1679922%2C1679920&_=1498566208688"
println(url.matches(regex))
}
@Test
def testGetVoteUpDown(): Unit = {
val url = "http://user.mahua.com/ajax/joke/checkJokesDynamic?callback=jQuery&joke_ids=1679937&_=1498571259447"
val resp: Response = org.apache.http.client.fluent.Request.Get(url)
.addHeader("Accept", "text/html,application/xhtml+xml,application/json;q=0.9,image/webp,*/*;q=0.8")
.addHeader("Accept-Encoding", "gzip, deflate, sdch")
.addHeader("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36")
.addHeader("Upgrade-Insecure-Requests", "1")
.addHeader("Proxy-Connection", "keep-alive")
.addHeader("DNT", "1")
.execute
val result = resp.returnContent.asString(Charset.forName("UTF-8"))
println(result)
}
}
开发者ID:sutine,项目名称:webant-workbench,代码行数:44,代码来源:PluginTest.scala
示例17: KuaidailiCrawlerTest
//设置package包名称以及导入依赖的类
package org.webant.plugin.test.kuaidaili
import java.io.IOException
import java.nio.charset.Charset
import org.jsoup.Jsoup
import org.junit.{After, Before, Test}
import org.scalatest.junit.AssertionsForJUnit
import scala.collection.JavaConverters._
class KuaidailiCrawlerTest extends AssertionsForJUnit {
@Before
def init(): Unit = {
}
@After
def exit() {
}
@Test
@throws[IOException]
def crawl() {
val regex = "http://www.kuaidaili.com/free/?\\w*/?\\d*/?"
val url = "http://www.kuaidaili.com/free/intr/1714/"
if (!url.matches(regex))
return
val resp = org.apache.http.client.fluent.Request.Get(url)
.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
.addHeader("Accept-Encoding", "gzip, deflate")
.addHeader("Accept-Language", "zh-CN,zh;q=0.8")
.addHeader("Cache-Control", "max-age=0")
.addHeader("Connection", "keep-alive")
.addHeader("Cookie", "channelid=0; sid=1499250960617393; _ga=GA1.2.1752332708.1497859110; _gid=GA1.2.235526105.1499251241; Hm_lvt_7ed65b1cc4b810e9fd37959c9bb51b31=1497859110; Hm_lpvt_7ed65b1cc4b810e9fd37959c9bb51b31=1499252564")
.addHeader("Upgrade-Insecure-Requests", "1")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36")
.execute
val result = resp.returnContent.asString(Charset.forName("UTF-8"))
val doc = Jsoup.parse(result, url)
val tds = doc.select("#list tbody tr").asScala.map(tr => {
tr.select("td").asScala.map(td => {
td.text()
})
})
println(tds)
}
}
开发者ID:sutine,项目名称:webant-workbench,代码行数:51,代码来源:KuaidailiCrawlerTest.scala
示例18: GuShiWenCrawlerTest
//设置package包名称以及导入依赖的类
package org.webant.plugin.test.gushiwen
import java.io.IOException
import java.nio.charset.Charset
import org.junit.{After, Before, Test}
import org.scalatest.junit.AssertionsForJUnit
import org.webant.plugin.zhihu.processor.{AnswersProcessor, ZhihuSeedProcessor}
class GuShiWenCrawlerTest extends AssertionsForJUnit {
@Before
def init(): Unit = {
}
@After
def exit() {
}
@Test
def testLoadIds(): Unit = {
val seed = new ZhihuSeedProcessor
val answer = new AnswersProcessor
val ids = seed.links()
val remainIds = ids.filter(answer.accept)
println(remainIds.size)
}
@Test
def testRegex(): Unit = {
val regex = "https://www.zhihu.com/api/v4/members/[0-9a-zA-Z-]*/answers?[\\w\\W]*"
val url = "https://www.zhihu.com/api/v4/members/ma-en-32/answers?include=data%5B*%5D.is_normal%2Cis_collapsed%2Ccollapse_reason%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Cmark_infos%2Ccreated_time%2Cupdated_time%2Creview_info%2Crelationship.is_authorized%2Cvoting%2Cis_author%2Cis_thanked%2Cis_nothelp%2Cupvoted_followees%3Bdata%5B*%5D.author.badge%5B%3F(type%3Dbest_answerer)%5D.topics&offset=20&limit=20&sort_by=created"
println(url.matches(regex))
}
@Test
@throws[IOException]
def crawl() {
val url = "http://www.gushiwen.org/default_3.aspx"
val body = ""
val resp = org.apache.http.client.fluent.Request.Get(url)
// .bodyString(body, ContentType.APPLICATION_FORM_URLENCODED)
.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
.addHeader("Accept-Encoding", "gzip, deflate")
.addHeader("Accept-Language", "zh-CN,zh;q=0.8")
.addHeader("Cache-Control", "max-age=0")
.addHeader("Connection", "keep-alive")
.addHeader("Cookie", "ASP.NET_SessionId=53xs3mimhjnhuoprpehzws0i; Hm_lvt_04660099568f561a75456483228a9516=1498717319; Hm_lpvt_04660099568f561a75456483228a9516=1498720515")
// .addHeader("If-Modified-Since", "Wed, 28 Jun 2017 08:59:13 GMT")
.addHeader("Referer", "http://www.gushiwen.org/")
.addHeader("Upgrade-Insecure-Requests", "1")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36")
.execute
val result = resp.returnContent.asString(Charset.forName("UTF-8"))
println(result)
}
}
开发者ID:sutine,项目名称:webant-workbench,代码行数:59,代码来源:GuShiWenCrawlerTest.scala
示例19: ZhihuCrawler
//设置package包名称以及导入依赖的类
package org.webant.plugin.test.zhihu
import java.io.IOException
import java.nio.charset.Charset
import org.apache.http.client.fluent.Response
import org.junit.{After, Before, Test}
import org.scalatest.junit.AssertionsForJUnit
import org.webant.plugin.zhihu.processor.{AnswersProcessor, ZhihuSeedProcessor}
class ZhihuCrawler extends AssertionsForJUnit {
@Before
def init(): Unit = {
}
@After
def exit() {
}
@Test
def testLoadIds(): Unit = {
val seed = new ZhihuSeedProcessor
val answer = new AnswersProcessor
val ids = seed.links()
val remainIds = ids.filter(answer.accept)
println(remainIds.size)
}
@Test
def testRegex(): Unit = {
val regex = "https://www.zhihu.com/api/v4/members/[0-9a-zA-Z-]*/answers?[\\w\\W]*"
val url = "https://www.zhihu.com/api/v4/members/ma-en-32/answers?include=data%5B*%5D.is_normal%2Cis_collapsed%2Ccollapse_reason%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Cmark_infos%2Ccreated_time%2Cupdated_time%2Creview_info%2Crelationship.is_authorized%2Cvoting%2Cis_author%2Cis_thanked%2Cis_nothelp%2Cupvoted_followees%3Bdata%5B*%5D.author.badge%5B%3F(type%3Dbest_answerer)%5D.topics&offset=20&limit=20&sort_by=created"
println(url.matches(regex))
}
@Test
@throws[IOException]
def crawl() {
val url: String = "https://www.zhihu.com/api/v4/members/huang-jie-rui-23/answers?offset=0&limit=20&sort_by=created&include=data[*].is_normal,is_collapsed,collapse_reason,suggest_edit,comment_count,can_comment,content,voteup_count,reshipment_settings,comment_permission,mark_infos,created_time,updated_time,review_info,relationship.is_authorized,voting,is_author,is_thanked,is_nothelp,upvoted_followees;data[*].author.badge[?(type=best_answerer)].topics"
val body: String = "offset=20&limit=20&sort_by=created&include=data[*].is_normal,is_collapsed,collapse_reason,suggest_edit,comment_count,can_comment,content,voteup_count,reshipment_settings,comment_permission,mark_infos,created_time,updated_time,review_info,relationship.is_authorized,voting,is_author,is_thanked,is_nothelp,upvoted_followees;data[*].author.badge[?(type=best_answerer)].topics"
val referer: String = "https://www.zhihu.com/people/sgai/answers"
val resp: Response = org.apache.http.client.fluent.Request.Get(url)
// .bodyString(body, ContentType.APPLICATION_FORM_URLENCODED)
.addHeader("Accept", "application/json, text/plain, */*")
.addHeader("Accept-Encoding", "gzip, deflate, br")
.addHeader("Accept-Language", "zh-CN,zh;q=0.8")
.addHeader("authorization", "oauth c3cef7c66a1843f8b3a9e6a1e3160e20")
.addHeader("Connection", "keep-alive")
.addHeader("Cookie", "q_c1=4e2c8fb281aa49f7a1a4c8f88297eb25|1497321957000|1497321957000; q_c1=ce4133c29ce34b8cb8a3d2f217706cee|1497321957000|1497321957000; aliyungf_tc=AQAAAOHxiwPxPQUAUb0Qt6/uDktO7KJF; capsion_ticket=\"2|1:0|10:1497930998|14:capsion_ticket|44:ZjRkNDVkNDEwYmY1NDZiNjk0ZjhlNjA1NGM3Mjk1ODk=|1f544f44ef3522b9bd1dede68727c906774eef7d8e1efc05e62b642bea3278ac\"; r_cap_id=\"MGQxNmI4MTViNDNkNDdkZDhiNDJjYmMxYjFlZTk2MTk=|1498653197|7a5cc12917ace5c66d6558b8d9639d3bdd9734f9\"; cap_id=\"Y2RjYzU4YjQ5MzRlNDEzOGE5NDlhMTgyYTU0Y2ZmNWM=|1498653197|5eb2b7e7932423a4f49322a0d7b0d4087b5536a0\"; d_c0=\"AIBCCu2_-wuPTv6gpIWSY62GJJWv1Q6X7vM=|1498653198\"; _zap=5da260eb-bc7d-4ee6-8563-ca7267dc83a7; __utma=51854390.1081252107.1498653231.1498653231.1498653231.1; __utmc=51854390; __utmz=51854390.1498653231.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmv=51854390.000--|3=entry_date=20170613=1; l_n_c=1; l_cap_id=\"NzFiNzIxZjM0YTZkNGRmYWJkMGU3NzliZjljYWRmZGQ=|1498653211|9028a58183ea376bf5dcc3be0014a071a6fb0a16\"; n_c=1; _xsrf=77f2b8a9-9707-4117-b1e6-2876f8f8405a")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36")
.addHeader("x-udid", "AIBCCu2_-wuPTv6gpIWSY62GJJWv1Q6X7vM=")
.execute
val result = resp.returnContent.asString(Charset.forName("GBK"))
println(result)
}
}
开发者ID:sutine,项目名称:webant-workbench,代码行数:59,代码来源:ZhihuCrawler.scala
示例20: TempFileWebCrawlerTest
//设置package包名称以及导入依赖的类
package org.zella.web
import java.util.logging.Level
import com.gargoylesoftware.htmlunit.{BrowserVersion, WebClient}
import com.google.common.truth.Truth._
import org.junit.{After, Before, Test}
class TempFileWebCrawlerTest {
//TODO mp3spbcrawler
val VALID_DOWNLOAD_LINK = "http://musicmp3spb.org/download/nude_city_life/67940862cca1c77354504829f3bfcb6f1480066258"
var webClient: WebClient = _
@Before def setup() {
webClient = new WebClient(BrowserVersion.FIREFOX_45)
webClient.getOptions.setThrowExceptionOnScriptError(false)
webClient.getOptions.setThrowExceptionOnFailingStatusCode(false)
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF)
}
@Test
def clickButton() {
val webCrawler = new TempFileWebCrawler(webClient)
//TODO move webClient.getPage(VALID_DOWNLOAD_LINK) to TempFileWebCrawler
val page = webCrawler.clickButton(webClient.getPage(VALID_DOWNLOAD_LINK))
assertThat(page.getTitleText).isEqualTo("TempFile.ru - ????????? ???????? ?????? ?? 200 ??. ?????????? ??????? ????????.")
}
@Test
def clickDownLoadLink() {
val webCrawler = new TempFileWebCrawler(webClient)
val page = webCrawler.clickButton(webClient.getPage(VALID_DOWNLOAD_LINK))
val link = webCrawler.clickDownloadLink(page)
assertThat(link).startsWith("http://tempfile.ru/download/")
}
@After def clickDownloadLink() {
webClient.close()
}
}
开发者ID:zella,项目名称:Mp3SpbDownloader,代码行数:47,代码来源:TempFileWebCrawlerTest.scala
注:本文中的org.junit.Before类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论