Commits

Konstantin Baierer committed 488def3

some tests for metaclass builder

  • Participants
  • Parent commits ba0a809

Comments (0)

Files changed (3)

File lib/MooseX/Semantic/Role/RdfExport.pm

     my $self = shift;
     my ($model) = @_;
     unless ($model) {
-        warn "No model supplied, create temporary model";
+        # warn "No model supplied, create temporary model";
         $model = RDF::Trine::Model->temporary_model;
     }
 

File t/data/person_moose_definition.ttl

 @prefix bio:    <http://purl.org/vocab/bio/0.1/> .
 @prefix schema: <http://schema.org/> .
 
-<http://myapp/whatever>
+<http://myapp/FoafMixin>
     a moose:Class ;
     moose:class_name "EmptyMoosePackage" ;
     moose:has_attribute <knows>,

File t/rdf_metabuilder.t

-use Test::More;
+use Test::More tests=>4;
 use Test::Moose;
 use RDF::Trine::Namespace qw(rdf);
 use RDF::Trine qw(iri);
 use MooseX::Semantic::MetaBuilder::Class;
 use MooseX::Semantic::MetaBuilder::Attribute;
 
-
-my $MOOSE = 'http://moose.perl.org/onto#';
-my $moose = RDF::Trine::Namespace->new($MOOSE);
 my $base_uri = 'http://myapp/';
 my $test_model = RDF::Trine::Model->temporary_model;
 RDF::Trine::Parser::Turtle->parse_file_into_model(
     't/data/person_moose_definition.ttl',
     $test_model,
 );
+
+my $MOOSE = 'http://moose.perl.org/onto#';
+my $moose = RDF::Trine::Namespace->new($MOOSE);
+my $myapp = RDF::Trine::Namespace->new($base_uri);
 # my $classes;
 
-warn ser_dump( $test_model );
+# warn ser_dump( $test_model );
 
 { 
     package EmptyMoosePackage;
     1;
 }
 
-my $classes_iter = $test_model->subjects( $rdf->type, $moose->Class );
-while (my $res = $classes_iter->next) {
-    my $metaclass = MooseX::Semantic::MetaBuilder::Class->new_from_model( $test_model, $res );
-    # warn Dumper $metaclass;
-    $metaclass->add_attributes_to_class( 'EmptyMoosePackage' );
-}
+ok(
+my $foaf_metaclass_builder = MooseX::Semantic::MetaBuilder::Class->new_from_model(
+    $test_model, 
+    $myapp->FoafMixin
+), 'loaded FoafMixin Metaclass Builder from model');
+is(scalar @{$foaf_metaclass_builder->has_attribute}, 2, 'FoafMixin Metaclass Builder has 2 attributes');
+
+is( scalar EmptyMoosePackage->meta->get_attribute_list, 0, 'EmptyMoosePackage has 0 attributes');
+# my $classes_iter = $test_model->subjects( $rdf->type, $moose->Class );
+# while (my $res = $classes_iter->next) {
+ # }
+$foaf_metaclass_builder->add_attributes_to_class( 'EmptyMoosePackage' );
+is( scalar EmptyMoosePackage->meta->get_attribute_list, 2, 'EmptyMoosePackage has 2 attributes');
 # warn Dumper(
     # EmptyMoosePackage->meta->get_attribute('knows')
 # );