35838396d839dcec5490802d7ad9908190a6ab1a9e565cf8d359e49241b06e5783ab12e4ff10bf71
 
 
1
/*
 
 
2
* LDIF
 
 
3
*
 
 
4
* Copyright 2011 Freie Universit├Ąt Berlin, MediaEvent Services GmbH & Co. KG
 
 
5
*
 
 
6
* Licensed under the Apache License, Version 2.0 (the "License");
 
 
7
* you may not use this file except in compliance with the License.
 
 
8
* You may obtain a copy of the License at
 
 
9
*
 
 
10
*      http://www.apache.org/licenses/LICENSE-2.0
 
 
11
*
 
 
12
* Unless required by applicable law or agreed to in writing, software
 
 
13
* distributed under the License is distributed on an "AS IS" BASIS,
 
 
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
 
15
* See the License for the specific language governing permissions and
 
 
16
* limitations under the License.
 
 
17
*/
 
 
18
 
 
 
19
package ldif.hadoop
 
 
20
 
 
 
21
import config.HadoopIntegrationConfig
 
 
22
import java.io.File
 
 
23
import org.scalatest.FlatSpec
 
 
24
import org.junit.runner.RunWith
 
 
25
import org.scalatest.junit.JUnitRunner
 
 
26
import ldif.entity.Node
 
 
27
import ldif.runtime.Quad
 
 
28
import org.scalatest.matchers.ShouldMatchers
 
 
29
import ldif.util.OutputValidator
 
 
30
 
 
 
31
 
 
 
32
@RunWith(classOf[JUnitRunner])
 
 
33
class HadoopIntegrationTest extends FlatSpec with ShouldMatchers {
 
 
34
 
 
 
35
  it should "run the hadoop integration flow correctly" in {
 
 
36
      // Run LDIF
 
 
37
      val configFile = loadConfig("ldif/hadoop/integrationJob.xml")
 
 
38
      val ldifOutput = runLdif(configFile, true)
 
 
39
 
 
 
40
      // Load results to compare with
 
 
41
      val ldimporterOuputUrl = getClass.getClassLoader.getResource("ldif/hadoop/result.nq")
 
 
42
      val ldimporterOuputFile = new File(ldimporterOuputUrl.toString.stripPrefix("file:"))
 
 
43
 
 
 
44
      // Check results
 
 
45
      OutputValidator.compare(ldifOutput, ldimporterOuputFile) should equal (0)
 
 
46
 
 
 
47
  }
 
 
48
 
 
 
49
 
 
 
50
    protected def loadConfig(config : String) =  {
 
 
51
      val configUrl = getClass.getClassLoader.getResource(config)
 
 
52
      new File(configUrl.toString.stripPrefix("file:"))
 
 
53
    }
 
 
54
 
 
 
55
    protected def runLdif(configFile : File, debugMode: Boolean = false) = {
 
 
56
      val integrator = new HadoopIntegrationJob(HadoopIntegrationConfig.load(configFile), debugMode)
 
 
57
      integrator.runIntegration
 
 
58
      (new File(integrator.config.outputFile)).listFiles().last
 
 
59
    }
 
 
60
 
 
 
61
}