diff options
author | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2011-01-31 15:00:27 +0100 |
---|---|---|
committer | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2011-01-31 15:00:27 +0100 |
commit | 6e5a780ba6ca83fd68267b0cc40f8943eb267827 (patch) | |
tree | 2f3aa64f2a1382284eedb6be71811d7dcb52470c /test | |
download | ecs2-6e5a780ba6ca83fd68267b0cc40f8943eb267827.tar.gz ecs2-6e5a780ba6ca83fd68267b0cc40f8943eb267827.zip |
Initial commit.
Diffstat (limited to 'test')
37 files changed, 1820 insertions, 0 deletions
diff --git a/test/fixtures/communities.yml b/test/fixtures/communities.yml new file mode 100644 index 0000000..a2a3f1d --- /dev/null +++ b/test/fixtures/communities.yml @@ -0,0 +1,27 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +public: + name: public + description: "Community for anonymous participants." +suv: + name: SUV + description: "Süddeutscher Uni-Verbund\r\nAlle Unis südlich des Mains." +wuv: + name: WUV + description: "Westdeutscher Uni-Verbund. Mal sehen, wie lange man hier die Zeilen\r\nmachen kann und wie sie nachher umgebrochen werden. Das kann wahrscheinlich\r\nbeliebig lange gehen, bis dass die Zeile aus dem Bildschirm hängt :)" diff --git a/test/fixtures/community_messages.yml b/test/fixtures/community_messages.yml new file mode 100644 index 0000000..6892df4 --- /dev/null +++ b/test/fixtures/community_messages.yml @@ -0,0 +1,31 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +numlab_ex1_to_suv: + message_id: 1 + community: suv + +numlab_ex1_to_wuv: + message_id: 1 + community: wuv + +numlab_ex1_to_public: + message_id: 1 + community: public + diff --git a/test/fixtures/ev_types.yml b/test/fixtures/ev_types.yml new file mode 100644 index 0000000..365c316 --- /dev/null +++ b/test/fixtures/ev_types.yml @@ -0,0 +1,35 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +created: + id: 1 + name: created + +destroyed: + id: 2 + name: destroyed + +updated: + id: 3 + name: updated + +notlinked: + id: 4 + name: notlinked diff --git a/test/fixtures/events.yml b/test/fixtures/events.yml new file mode 100644 index 0000000..017a7ff --- /dev/null +++ b/test/fixtures/events.yml @@ -0,0 +1,19 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html diff --git a/test/fixtures/identities.yml b/test/fixtures/identities.yml new file mode 100644 index 0000000..3c87c80 --- /dev/null +++ b/test/fixtures/identities.yml @@ -0,0 +1,43 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +stgt_id1: + name: my_secret_identity + description: "Einfach eine Dummy Identiy." + participant_id: 1 + +stgt_id2: + name: myid + description: "Zertifikats-ID\r\nZentrale E-Lernplattform am Rechenzentrum." + participant_id: 1 + +ulm_id1: + name: ulama + description: "LDAP Authentication ID." + participant_id: 2 + +numlab_comp_id1: + name: sunito + description: + participant_id: 3 + +numlab_teacher_id1: + name: trulane + description: + participant_id: 4 + diff --git a/test/fixtures/membership_messages.yml b/test/fixtures/membership_messages.yml new file mode 100644 index 0000000..dbfd8e0 --- /dev/null +++ b/test/fixtures/membership_messages.yml @@ -0,0 +1,54 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +1: + id: 1 + membership_id: 1 #stuttgart_suv + message_id: 1 #numlab_exercise_1 + +2: + id: 2 + membership_id: 2 #ulm_wuv + message_id: 2 #numlab_exercise_2 + +3: + id: 3 + membership_id: 4 #ulm_suv_4 + message_id: 3 #numlab_sol_3 + +4: + id: 4 + membership_id: 2 #ulm_wuv + message_id: 4 #cc_courselink_1 + +5: + id: 5 + membership_id: 3 #stuttgart_wuv + message_id: 6 #numlab_ulm_exercise_1 + +6: + id: 6 + membership_id: 2 #ulm_wuv + message_id: 1 #numlab_exercise_1 + +7: + id: 7 + membership_id: 4 #ulm_suv + message_id: 2 #numlab_exercise_2 diff --git a/test/fixtures/memberships.yml b/test/fixtures/memberships.yml new file mode 100644 index 0000000..934f411 --- /dev/null +++ b/test/fixtures/memberships.yml @@ -0,0 +1,52 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +stgt_suv: + id: 1 + participant_id: 1 + community: suv + +ulm_wuv: + id: 2 + participant_id: 2 + community: wuv + +stgt_wuv: + id: 3 + participant_id: 1 + community: wuv + +ulm_suv: + id: 4 + participant_id: 2 + community: suv + +numlab_comp: + id: 5 + participant_id: 3 + community: public + +stgt_public: + id: 6 + participant_id: 1 + community: public + +numlab_teacher: + id: 7 + participant_id: 4 + community: public diff --git a/test/fixtures/messages.yml b/test/fixtures/messages.yml new file mode 100644 index 0000000..9fdebd6 --- /dev/null +++ b/test/fixtures/messages.yml @@ -0,0 +1,62 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +numlab_ex1: + id: 1 + ressource: numlab_ex + content_type: application/json + sender: 1 + body: "Hallo Ihr da im Radio.\r\n" + +numlab_ex2: + id: 2 + ressource: numlab_ex + content_type: application/json + sender: 1 + body: "Achtung ein Kartoon.\r\n" + +numlab_sol: + id: 3 + ressource: numlab_solutions + content_type: application/json + sender: 1 + body: "Eine gute Loesung.\r\n" + +cc_course1: + id: 4 + ressource: cc_course + content_type: application/json + sender: 1 + body: "Der ultimative Kurs.\r\n" + +no_rec: + id: 5 + ressource: cc_course + content_type: application/json + sender: 19900 + body: "Dieser Kurslink hat keinen Empfänger." + +numlab_ulm_ex1: + id: 6 + ressource: numlab_ex + content_type: application/json + sender: 2 + body: "Ne superschwere Aufgabe aus Ulm.\r\n" + diff --git a/test/fixtures/organizations.yml b/test/fixtures/organizations.yml new file mode 100644 index 0000000..288b9ca --- /dev/null +++ b/test/fixtures/organizations.yml @@ -0,0 +1,32 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +NA: + name: not available + abrev: N/A + description: This is epecially for anonymous participants. + +uni_stgt: + name: Universität Stuttgart + abrev: S + description: Technische Universität Stuttgart + +uni_ulm: + name: Universität Ulm + abrev: U + description: Universität Stuttgart diff --git a/test/fixtures/participants.yml b/test/fixtures/participants.yml new file mode 100644 index 0000000..97e3a0b --- /dev/null +++ b/test/fixtures/participants.yml @@ -0,0 +1,57 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +ilias_stgt: + id: 1 + name: Ilias Uni Stuttgart + dns: ilias3.uni-stuttgart.de + email: klaus.vorkauf@uni-stuttgart.de + description: Zentrale Lernplattform + organization: uni_stgt + ttl: <%= Time.gm(1970,1,1).to_s(:db) %> + anonymous: false + +ilias_ulm: + id: 2 + name: Ilias Uni Ulm + dns: ilias3.uni-ulm.de + email: matthias.schneiderhahn@uni-ulm.de.de + description: Zentrale Lernplattform + organization: uni_ulm + ttl: <%= Time.gm(1970,1,1).to_s(:db) %> + anonymous: false + +numlab_comp: + id: 3 + name: Computation client + dns: N/A + email: rudlof@rus.uni-stuttgart.de + description: Computation client of NumLab service. + organization: uni_stgt + ttl: <%= Time.gm(1970,1,1).to_s(:db) %> + anonymous: false + +numlab_teacher: + id: 4 + name: Teacher client + dns: N/A + email: adjibadji@rus.uni-stuttgart.de + description: Teacher client of NumLab service. + organization: uni_stgt + ttl: <%= Time.gm(1970,1,1).to_s(:db) %> + anonymous: false diff --git a/test/fixtures/ressource_monitors.yml b/test/fixtures/ressource_monitors.yml new file mode 100644 index 0000000..7622c09 --- /dev/null +++ b/test/fixtures/ressource_monitors.yml @@ -0,0 +1,24 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + lock_version: 0 + monitor_counter: 0 + name: queue diff --git a/test/fixtures/ressources.yml b/test/fixtures/ressources.yml new file mode 100644 index 0000000..d66f17a --- /dev/null +++ b/test/fixtures/ressources.yml @@ -0,0 +1,44 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +numlab_ex: + namespace: numlab + ressource: exercises + postroute: true + events: true + + +numlab_results: + namespace: numlab + ressource: results + postroute: false + events: true + +numlab_solutions: + namespace: numlab + ressource: solutions + postroute: false + events: true + +cc_course: + namespace: cc + ressource: course + postroute: false + events: true + diff --git a/test/functional/admin/participants_controller_test.rb b/test/functional/admin/participants_controller_test.rb new file mode 100644 index 0000000..b9133a9 --- /dev/null +++ b/test/functional/admin/participants_controller_test.rb @@ -0,0 +1,46 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + + +class Admin::ParticipantsControllerTest < ActionController::TestCase + TTL = 3600 # seconds, how long an anonymous participant lives + test "create participant and postrouting" do + params = { + :participant => { + "name"=> "testclient", + "identities_attributes"=>{"0"=>{"name"=>"test", "description"=>"only for test"}}, + "community_ids"=>[communities(:wuv).id], + "description"=>"Dieser Participant wird zum Testen kreiert.", + "dns"=>"N/A", + "organization_id"=>Organization.find_by_name("not available").id, + "email"=>"N/A", + "ttl"=> DateTime.now.utc + TTL.seconds, + "anonymous"=>false, + "community_selfrouting"=>false + } + } + assert_difference('Participant.count') do + post :create, params + end + assert_equal('Participant was successfully created.',flash[:notice]) + assert_equal(communities(:wuv).id, Participant.find_by_name("testclient").communities.first.id) + assert_equal(1,Participant.find_by_name("testclient").memberships.first.membership_messages.count) + end +end diff --git a/test/functional/events_controller_test.rb b/test/functional/events_controller_test.rb new file mode 100644 index 0000000..28e5fce --- /dev/null +++ b/test/functional/events_controller_test.rb @@ -0,0 +1,27 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class EventsControllerTest < ActionController::TestCase + test "index" do + @request.env["X-EcsAuthId"] = identities(:ulm_id1).name + get :index + assert_response 200 + end +end diff --git a/test/functional/memberships_controller_test.rb b/test/functional/memberships_controller_test.rb new file mode 100644 index 0000000..4902434 --- /dev/null +++ b/test/functional/memberships_controller_test.rb @@ -0,0 +1,45 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class MembershipsControllerTest < ActionController::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end + + test "create_anonymous_client" do + @request.env["CONTENT_TYPE"] = "application/json" + get :index + + assert_response 200 + assert_match /ecs_anonymous=.*/, @response.headers["Set-Cookie"].to_s + end + + test "prettyfied memberships" do + @request.env["ACCEPT"] = "application/json" + get :index + assert_response 200 + f = StringIO.open @response.body + b = f.readlines + f.close + assert b.length > 1, "/memberships representation is not prettyfied json.\nMaybe json-pretty doesn't work.\nMaybe old gems ? Especially the json gem." + end + +end diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb new file mode 100644 index 0000000..c4b117d --- /dev/null +++ b/test/functional/messages_controller_test.rb @@ -0,0 +1,289 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class MessagesControllerTest < ActionController::TestCase + test "index" do + @request.env["X-EcsAuthId"] = identities(:ulm_id1).name + @request.set_REQUEST_URI("/numlab/exercises") + get :index + assert_response 200 + assert_equal [1,2], assigns(:list).map {|e| e.id} + end + + test "show first exercise as a receiver" do + @request.env["X-EcsAuthId"] = identities(:ulm_id1).name + @request.set_REQUEST_URI("/numlab/exercises") + get :show, { :id => messages(:numlab_ex1).id } + assert_response 200 + assert_equal "Hallo Ihr da im Radio.", @response.body.strip + assert_equal "X-EcsSender: "+memberships(:stgt_wuv).id.to_s, "X-EcsSender: "+@response.header['X-EcsSender'] + assert_equal "X-EcsReceiverCommunities: "+communities(:wuv).id.to_s, "X-EcsReceiverCommunities: "+@response.header['X-EcsReceiverCommunities'] + end + + test "show solution" do + @request.env["X-EcsAuthId"] = identities(:ulm_id1).name + @request.set_REQUEST_URI("/numlab/solutions/3") + get :show, { :id => messages(:numlab_sol).id } + logger.debug "request.path = #{@request.path}" + logger.debug "app_namespace = #{assigns(:app_namespace)}" + logger.debug "ressource_name = #{assigns(:ressource_name)}" + assert_response 200 + end + + # not a receiver or sender of :numlab_ex1 + test "show forbidden exercise" do + @request.env["X-EcsAuthId"] = identities(:numlab_comp_id1).name + @request.set_REQUEST_URI("/numlab/exercises/#{messages(:numlab_ulm_ex1).id.to_s}") + get :show, { :id => messages(:numlab_ulm_ex1).id } + logger.debug "request.path = #{@request.path}" + assert_response 403 + end + + test "show exercise as original sender but not as a receiver" do + @request.env["X-EcsAuthId"] = identities(:ulm_id1).name + @request.set_REQUEST_URI("/numlab/exercises") + get :show, { :id => messages(:numlab_ulm_ex1).id } + logger.debug "request.path = #{@request.path}" + assert_response 200 + assert !@response.header.has_key?('X-EcsSender') + assert !@response.header.has_key?('X-EcsReceiverCommunities') + end + + test "create_X-EcsReceiverMemberships" do + @request.env["RAW_POST_DATA"] = "hallole" + @request.env["CONTENT_TYPE"] = "text/html" + @request.env["X-EcsAuthId"] = identities(:stgt_id1).name + @request.env["X-EcsReceiverMemberships"] = memberships(:ulm_wuv).id.to_s + @request.set_REQUEST_URI("/numlab/exercises") + mm_count = MembershipMessage.all.count + post :create + assert_response 201 + assert_equal assigns(:record).sender, assigns(:participant).id + assert_equal mm_count+1, MembershipMessage.all.count + assert_match /^.*\/numlab\/exercises\/[0-9]+$/, @response.header['LOCATION'] + end + + test "create_X-EcsReceiverCommunities_single" do + @request.env["RAW_POST_DATA"] = "hallole" + @request.env["CONTENT_TYPE"] = "text/html" + @request.env["X-EcsAuthId"] = identities(:stgt_id1).name + @request.env["X-EcsReceiverCommunities"] = communities(:suv).name + mm_count = MembershipMessage.all.count + post :create + + assert_response 201 + assert_equal assigns(:record).sender, assigns(:participant).id + assert_equal mm_count+1, MembershipMessage.all.count + end + + test "create_X-EcsReceiverCommunities_multi" do + @request.env["RAW_POST_DATA"] = "hallole" + @request.env["CONTENT_TYPE"] = "text/html" + @request.env["X-EcsAuthId"] = identities(:stgt_id1).name + @request.env["X-EcsReceiverCommunities"] = communities(:suv).name + "," + communities(:public).name + mm_count = MembershipMessage.all.count + post :create + assert_response 201 + assert_equal assigns(:record).sender, assigns(:participant).id + assert_equal mm_count+3, MembershipMessage.all.count + end + + test "create_X-EcsReceiverCommunities_multi_string_and_number" do + @request.env["RAW_POST_DATA"] = "hallole" + @request.env["CONTENT_TYPE"] = "text/html" + @request.env["X-EcsAuthId"] = identities(:stgt_id1).name + @request.env["X-EcsReceiverCommunities"] = communities(:suv).name + "," + communities(:public).id.to_s + mm_count = MembershipMessage.all.count + post :create + assert_response 201 + assert_equal assigns(:record).sender, assigns(:participant).id + assert_equal mm_count+3, MembershipMessage.all.count + end + + test "create without content-type header" do + @request.env["RAW_POST_DATA"] = "hallole" + @request.env["X-EcsAuthId"] = identities(:stgt_id1).name + @request.env["X-EcsReceiverMemberships"] = memberships(:ulm_wuv).id.to_s + post :create + assert_response 400 + end + + test "create without body" do + @request.env["CONTENT_TYPE"] = "text/html" + @request.env["X-EcsAuthId"] = identities(:stgt_id1).name + @request.env["X-EcsReceiverMemberships"] = memberships(:ulm_wuv).id.to_s + post :create + assert_response 400 + end + + test "update" do + @request.env["RAW_POST_DATA"] = "neuer Text" + @request.env["CONTENT_TYPE"] = "text/html" + @request.env["X-EcsAuthId"] = identities(:stgt_id1).name + @request.env["X-EcsReceiverMemberships"] = memberships(:ulm_wuv).id.to_s + @request.set_REQUEST_URI("/numlab/exercises") + post :update, { :id => messages(:numlab_ex2).id } + assert_response 200 + end + + test "update without ownership" do + @request.env["RAW_POST_DATA"] = "neuer Text" + @request.env["CONTENT_TYPE"] = "text/html" + @request.env["X-EcsAuthId"] = identities(:ulm_id1).name + @request.env["X-EcsReceiverMemberships"] = memberships(:ulm_wuv).id.to_s + @request.set_REQUEST_URI("/numlab/exercises") + post :update, { :id => messages(:numlab_ex2).id } + assert_response 403 + end + + test "delete_postrouted_message_as_owner_with_references_in_place" do + @request.set_REQUEST_URI("/numlab/exercises/99999") + @request.env["X-EcsAuthId"] = identities(:ulm_id1).name + assert MembershipMessage.find_all_by_message_id(messages(:numlab_ulm_ex1)).count > 0 + post :destroy, { :id => messages(:numlab_ulm_ex1).id } + logger.debug "@request.path = "+@request.path + assert_response 200 + get :show, { :id => messages(:numlab_ulm_ex1).id } + assert_response 404 + assert_equal 0, MembershipMessage.find_all_by_message_id(messages(:numlab_ulm_ex1)).count + # message is only tagged as removed (events on). physically it's still there. + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(messages(:numlab_ulm_ex1)) } + end + + test "delete_postrouted_message_as_none_owner_with_references_in_place" do + @request.set_REQUEST_URI("/numlab/exercises/99999") + @request.env["X-EcsAuthId"] = identities(:stgt_id1).name + mm_count = MembershipMessage.all.count + # destroy message through receiver and none owner + post :destroy, { :id => messages(:numlab_ulm_ex1).id } + logger.debug "@request.path = "+@request.path + assert_response 200 + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(@request.parameters[:id]) } + assert_equal 0, MembershipMessage.find_all_by_message_id(@request.parameters[:id]).count + end + + test "delete_none_postrouted_message_as_none_owner_with_last_reference_in_place" do + @request.env["RAW_POST_DATA"] = "Diese Nachricht ist volatil.\r\n" + @request.env["CONTENT_TYPE"] = "text/plain" + @request.env["X-EcsAuthId"] = identities(:stgt_id1).name + @request.env["X-EcsReceiverMemberships"] = memberships(:numlab_comp).id.to_s + @request.set_REQUEST_URI("/numlab/solutions") + mm_count = MembershipMessage.all.count + post :create + assert_response 201 + assert_equal assigns(:record).sender, assigns(:participant).id + assert_equal mm_count+1, MembershipMessage.all.count + # destroy message through receiver + @request.set_REQUEST_URI("/numlab/solutions") + @request.env["X-EcsAuthId"] = identities(:numlab_comp_id1).name + /[0-9]+$/ =~ @response.header['LOCATION'] + post :destroy, { :id => $~.to_s.to_i } + assert_response 200 + assert_equal $~.to_s, @request.parameters[:id] + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(@request.parameters[:id]) } + assert_nil MembershipMessage.find_by_message_id(@request.parameters[:id]) + end + + test "delete_none_postrouted_message_as_none_owner_with_references_in_place" do + @request.env["RAW_POST_DATA"] = "Diese Nachricht ist volatil.\r\n" + @request.env["CONTENT_TYPE"] = "text/plain" + @request.env["X-EcsAuthId"] = identities(:stgt_id1).name + @request.env["X-EcsReceiverMemberships"] = memberships(:numlab_comp).id.to_s+","+memberships(:numlab_teacher).id.to_s + @request.set_REQUEST_URI("/numlab/solutions") + mm_count = MembershipMessage.all.count + post :create + assert_response 201 + assert_equal assigns(:record).sender, assigns(:participant).id + assert_equal mm_count+2, MembershipMessage.all.count + /[0-9]+$/ =~ @response.header['LOCATION'] + assert_equal 2, MembershipMessage.find_all_by_message_id($~.to_s.to_i).count + # destroy message through receiver + @request.set_REQUEST_URI("/numlab/solutions") + @request.env["X-EcsAuthId"] = identities(:numlab_comp_id1).name + post :destroy, { :id => $~.to_s.to_i } + assert_response 200 + assert_equal $~.to_s, @request.parameters[:id] + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(@request.parameters[:id]) } + assert_equal 1, MembershipMessage.find_all_by_message_id($~.to_s.to_i).count + end + + # Queue tests + # + test "fifo get idempotent" do + @request.env["X-EcsAuthId"] = identities(:ulm_id1).name + @request.set_REQUEST_URI("/numlab/exercises") + get :fifo + assert_response 200 + assert_equal "Hallo Ihr da im Radio.", @response.body.strip + get :fifo + assert_response 200 + assert_equal "Hallo Ihr da im Radio.", @response.body.strip + end + + test "fifo get not idempotent" do + @request.env["X-EcsAuthId"] = identities(:ulm_id1).name + @request.set_REQUEST_URI("/numlab/exercises") + post :fifo + assert_response 200 + assert_equal "Hallo Ihr da im Radio.", @response.body.strip + get :fifo + assert_response 200 + assert_not_equal "Hallo Ihr da im Radio.", @response.body.strip + assert_equal "Achtung ein Kartoon.", @response.body.strip + end + + test "lifo get idempotent" do + @request.env["X-EcsAuthId"] = identities(:ulm_id1).name + @request.set_REQUEST_URI("/numlab/exercises") + get :lifo + assert_response 200 + assert_equal "Achtung ein Kartoon.", @response.body.strip + get :lifo + assert_response 200 + assert_equal "Achtung ein Kartoon.", @response.body.strip + end + + test "lifo get not idempotent" do + @request.env["X-EcsAuthId"] = identities(:ulm_id1).name + @request.set_REQUEST_URI("/numlab/exercises") + post :lifo + assert_response 200 + assert_equal "Achtung ein Kartoon.", @response.body.strip + get :lifo + assert_response 200 + assert_not_equal "Achtung ein Kartoon.", @response.body.strip + assert_equal "Hallo Ihr da im Radio.", @response.body.strip + end + +# anonymous clients +# + + test "create anonymous client" do + @request.env["CONTENT_TYPE"] = "application/json" + @request.set_REQUEST_URI("/numlab/exercises") + mm_count = MembershipMessage.all.count + get :index + assert_response 200 + assert_match /ecs_anonymous=.*/, @response.headers["Set-Cookie"].to_s + assert_equal mm_count+1, MembershipMessage.all.count + end + + +end diff --git a/test/functional/queue_controller_test.rb b/test/functional/queue_controller_test.rb new file mode 100644 index 0000000..024d366 --- /dev/null +++ b/test/functional/queue_controller_test.rb @@ -0,0 +1,26 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class QueueControllerTest < ActionController::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/integration/community_messages_test.rb b/test/integration/community_messages_test.rb new file mode 100644 index 0000000..a40d799 --- /dev/null +++ b/test/integration/community_messages_test.rb @@ -0,0 +1,64 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class CommunityMessagesTest < ActionController::IntegrationTest + fixtures :all + + BODY_DATA = "hallole" + + def sender_headers + @headers ||= {} + @headers['HTTP_ACCEPT'] = 'text/plain' + @headers['CONTENT_TYPE'] = 'text/plain' + @participant = identities(:stgt_id1).participant + @headers["X-EcsAuthId"] = identities(:stgt_id1).name + @headers["X-EcsReceiverCommunities"] = communities(:suv).name + ',' + communities(:wuv).name + @headers["X-EcsReceiverMemberships"] = "" + end + + def setup + end + + def test_new_jointable_entries + sender_headers + post '/numlab/exercises', BODY_DATA, @headers + assert_response 201 + mid = URI.split(headers["Location"])[5].sub(/.*\/(.*)/, '\1') + assert Message.find(mid).communities.map{|c| c.name}.include?(communities(:suv).name) + assert Message.find(mid).communities.map{|c| c.name}.include?(communities(:wuv).name) + assert_equal 2, Message.find(mid).communities.length + end + + def test_if_jointable_entries_will_be_deleted + r=Ressource.find_by_namespace_and_ressource("numlab","exercises");r.events=false;r.save! + cm_count = CommunityMessage.all.length + sender_headers + post '/numlab/exercises', BODY_DATA, @headers + assert_equal cm_count+2, CommunityMessage.all.length # addressed to two communities + location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1') + mid = URI.split(headers["Location"])[5].sub(/.*\/(.*)/, '\1') + sender_headers + delete '/numlab/'+location, nil, @headers + assert_response 200 + assert_equal cm_count, CommunityMessage.all.length + end + +end + diff --git a/test/integration/ressource_test.rb b/test/integration/ressource_test.rb new file mode 100644 index 0000000..a24dae5 --- /dev/null +++ b/test/integration/ressource_test.rb @@ -0,0 +1,332 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class RessourceTest < ActionController::IntegrationTest + fixtures :all + + def setup + # delete all messages for sender and receiver_1 + + end + + BODY_DATA = "hallole" + + def sender_headers + @headers ||= {} + @headers['HTTP_ACCEPT'] = 'text/plain' + @headers['CONTENT_TYPE'] = 'text/plain' + @participant = identities(:stgt_id1).participant + @headers["X-EcsAuthId"] = identities(:stgt_id1).name + @headers["X-EcsReceiverCommunities"] = communities(:suv).name + @headers["X-EcsReceiverMemberships"] = "" + end + + def sender2_headers + @headers ||= {} + @headers['HTTP_ACCEPT'] = 'text/plain' + @headers['CONTENT_TYPE'] = 'text/plain' + @participant = identities(:stgt_id1).participant + @headers["X-EcsAuthId"] = identities(:stgt_id1).name + @headers["X-EcsReceiverCommunities"] = communities(:public).name + @headers["X-EcsReceiverMemberships"] = "" + end + + def receiver_1_headers + @headers ||= {} + @headers['HTTP_ACCEPT'] = 'text/plain' + @headers['CONTENT_TYPE'] = 'text/plain' + @participant = identities(:ulm_id1).participant + @headers["X-EcsAuthId"] = identities(:ulm_id1).name + @headers["X-EcsReceiverCommunities"] = communities(:suv).name + end + + def receiver_2_headers + @headers ||= {} + @headers['HTTP_ACCEPT'] = 'text/plain' + @headers['CONTENT_TYPE'] = 'text/plain' + @participant = identities(:numlab_teacher_id1).participant + @headers["X-EcsAuthId"] = identities(:numlab_teacher_id1).name + @headers["X-EcsReceiverCommunities"] = communities(:public).name + end + + def receiver_3_headers + @headers ||= {} + @headers['HTTP_ACCEPT'] = 'text/plain' + @headers['CONTENT_TYPE'] = 'text/plain' + @participant = identities(:numlab_comp_id1).participant + @headers["X-EcsAuthId"] = identities(:numlab_comp_id1).name + @headers["X-EcsReceiverCommunities"] = communities(:public).name + end + + def test_community_selfrouting + sender_headers + @participant.community_selfrouting=true;@participant.save! + location = "" + post '/numlab/exercises', BODY_DATA, @headers + assert_response 201 + location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1') + logger.info('headers["Location"]: '+headers["Location"]) + logger.info('location: '+location) + sender_headers + get '/numlab/exercises', nil, @headers + assert_response 200 + assert response.body.index(location) + end + + def test_community_no_selfrouting + sender_headers + location = "" + @participant.community_selfrouting=false;@participant.save! + post '/numlab/exercises', BODY_DATA, @headers + assert_response 201 + location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1') + logger.info('headers["Location"]: '+headers["Location"]) + logger.info('location: '+location) + sender_headers + assert !@participant.community_selfrouting + get '/numlab/exercises', nil, @headers + assert_response 200 + assert_nil response.body.index(location) + end + + + + + # events true + # postrouted true + # community_selfrouting false + # + # 1.0 Create exercise. + # 1.1 Test index of sender and other receivers. + # The new exercise should be shown on all indexes. + # 1.2 Test via GET /numlab/exercises/lifo of sender and other receivers. + # The new exercise should only be shown by receivers not by sender. + # 1.3 Test via GET /numlab/exercises/<id> of sender and other receivers. + # The new exercise should be shown by sender and other receivers. + # 1.4 Test if all receiver participants get an "created" event. + # The new event should be shown by sender and other receivers. + # 1.5 Pop sender and all receiver events. + def test_create + r=Ressource.find_by_namespace_and_ressource("numlab","exercises");r.postroute=true;r.save! + r=Ressource.find_by_namespace_and_ressource("numlab","exercises");r.events=true;r.save! + # 1.0 + sender_headers + location = "" + post '/numlab/exercises', BODY_DATA, @headers + assert_response 201 + location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1') + logger.info('headers["Location"]: '+headers["Location"]) + logger.info('location: '+location) + # 1.1 + sender_headers + get '/numlab/exercises', nil, @headers + assert_response 200 + assert_nil response.body.index(location) + receiver_1_headers + get '/numlab/exercises', nil, @headers + assert_response 200 + assert response.body.index(location) + # 1.2 + sender_headers + get '/numlab/exercises/lifo', nil, @headers + assert_response 200 + assert_nil response.body.index(BODY_DATA) + receiver_1_headers + get '/numlab/exercises/lifo', nil, @headers + assert_response 200 + assert response.body.index(BODY_DATA) + # 1.3 + sender_headers + get '/numlab/'+location, nil, @headers + assert_response 200 + assert response.body.index(BODY_DATA) + receiver_1_headers + get '/numlab/'+location, nil, @headers + assert_response 200 + assert response.body.index(BODY_DATA) + # 1.4 + sender_headers + get '/events', nil, @headers + assert_response 200 + assert_nil response.body.index(/.*?#{location}.*?created.*/) + receiver_1_headers + get '/events', nil, @headers + assert_response 200 + assert response.body.index(/.*?#{location}.*?created.*/) + # 1.5 + sender_headers + post '/events/fifo', nil, @headers + logger.info("response body:\n"+response.body) + assert_response 200 + assert_nil response.body.index(location) + sender_headers + post '/events/fifo', nil, @headers + assert_response 200 + assert_nil response.body.index(location) + receiver_1_headers + post '/events/fifo', nil, @headers + assert_response 200 + assert response.body.index(location) + receiver_1_headers + get '/events/fifo', nil, @headers + assert_response 200 + assert_nil response.body.index(location) + end + + # events true/false + # postrouted true/false + # + # 1.0 Delete exercise through the owner. + # 1.1 Test index of sender and other receivers. + # There shoudn't be any exercise on the index + # 1.2 Test if all receiver participants get an "destroyed" event. + # 1.3 Test if the deleted ressource is still in message table if events true + # otherwise the message shoud have been removed. + # 2.0 Pop all receiver destroyed events. + # 2.1 Test if the ressource was deleted from message table. + def test_delete_as_owner + p = lambda do |ev| + # 1.0 + sender_headers + location = "" + post '/numlab/exercises', BODY_DATA, @headers + assert_response 201 + location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1') + sender_headers + delete '/numlab/'+location, nil, @headers + assert_response 200 + # 1.1 + sender_headers + get '/numlab/exercises', nil, @headers + assert_response 200 + assert_nil response.body.index(location) + receiver_1_headers + get '/numlab/exercises', nil, @headers + assert_response 200 + assert_nil response.body.index(location) + # 1.2 + sender_headers + get '/events', nil, @headers + assert_response 200 + assert_nil(response.body.index(/.*?#{location}.*?destroyed.*/)) + receiver_1_headers + get '/events', nil, @headers + assert_response 200 + if ev + assert(response.body.index(/.*?#{location}.*?destroyed.*/)) + else + assert_nil(response.body.index(/.*?#{location}.*?destroyed.*/)) + end + # 1.3 + id = location.sub(/.*\/(.*)$/,'\1').to_i + if ev + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + assert(Message.find(id).removed) + else + assert_raise(ActiveRecord::RecordNotFound) { Message.find(id) } + end + # 2.0 + sender_headers + post '/events/fifo', nil, @headers # created event + assert_response 200 + assert_nil(response.body.index(/.*?#{location}.*?created.*/)) + sender_headers + post '/events/fifo', nil, @headers # destroyed event + assert_response 200 + if ev + assert_nil(response.body.index(/.*?#{location}.*?destroyed.*/)) + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + else + assert_nil(response.body.index(/.*?#{location}.*?destroyed.*/)) + assert_raise(ActiveRecord::RecordNotFound) { Message.find(id) } + end + receiver_1_headers + post '/events/fifo', nil, @headers # created event + assert_response 200 + if ev + assert(response.body.index(/.*?#{location}.*?created.*/)) + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + else + assert_nil(response.body.index(/.*?#{location}.*?created.*/)) + assert_raise(ActiveRecord::RecordNotFound) { Message.find(id) } + end + receiver_1_headers + post '/events/fifo', nil, @headers # destroyed event + assert_response 200 + if ev + assert(response.body.index(/.*?#{location}.*?destroyed.*/)) + else + assert_nil(response.body.index(/.*?#{location}.*?destroyed.*/)) + end + assert_raise(ActiveRecord::RecordNotFound) { Message.find(id) } + end + r=Ressource.find_by_namespace_and_ressource("numlab","exercises");r.events=true;r.save! + p.call(true) + r=Ressource.find_by_namespace_and_ressource("numlab","exercises");r.postroute=false;r.save! + p.call(true) + r=Ressource.find_by_namespace_and_ressource("numlab","exercises");r.events=false;r.save! + p.call(false) + r=Ressource.find_by_namespace_and_ressource("numlab","exercises");r.postroute=true;r.save! + p.call(false) + end + + # events true + # postrouted false + # community_selfrouting false + # + # 1.0 Delete exercise through non owner + # 1.1 Test index + def test_delete_as_non_owner + r=Ressource.find_by_namespace_and_ressource("numlab","exercises");r.events=true;r.save! + #p.call(true) + r=Ressource.find_by_namespace_and_ressource("numlab","exercises");r.postroute=false;r.save! + #p.call(true) + sender2_headers + @participant.community_selfrouting=false;@participant.save! + location = "" + post '/numlab/exercises', BODY_DATA, @headers + assert_response 201 + location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1') + id = location.sub(/.*\/(.*)$/,'\1').to_i + sender2_headers + get '/numlab/'+location, nil, @headers + assert_response 200 + assert response.body.index(BODY_DATA) + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + assert !Message.find(id).removed + receiver_1_headers + delete '/numlab/'+location, nil, @headers + assert_response 404 + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + assert !Message.find(id).removed + receiver_2_headers + delete '/numlab/'+location, nil, @headers + assert_response 200 + assert response.body.index(BODY_DATA) + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + assert !Message.find(id).removed + receiver_3_headers + delete '/numlab/'+location, nil, @headers + assert_response 200 + assert response.body.index(BODY_DATA) + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + assert Message.find(id).removed + end +end diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb new file mode 100644 index 0000000..88db53e --- /dev/null +++ b/test/performance/browsing_test.rb @@ -0,0 +1,27 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' +require 'performance_test_help' + +# Profiling results for each test method are written to tmp/performance. +class BrowsingTest < ActionController::PerformanceTest + def test_homepage + get '/' + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..392100b --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,60 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +ENV["RAILS_ENV"] = "test" +require File.expand_path(File.dirname(__FILE__) + "/../config/environment") +require 'test_help' + +class ActiveSupport::TestCase + # Transactional fixtures accelerate your tests by wrapping each test method + # in a transaction that's rolled back on completion. This ensures that the + # test database remains unchanged so your fixtures don't have to be reloaded + # between every test method. Fewer database queries means faster tests. + # + # Read Mike Clark's excellent walkthrough at + # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting + # + # Every Active Record database supports transactions except MyISAM tables + # in MySQL. Turn off transactional fixtures in this case; however, if you + # don't care one way or the other, switching from MyISAM to InnoDB tables + # is recommended. + # + # The only drawback to using transactional fixtures is when you actually + # need to test transactions. Since your test is bracketed by a transaction, + # any transactions started in your code will be automatically rolled back. + self.use_transactional_fixtures = true + + # Instantiated fixtures are slow, but give you @david where otherwise you + # would need people(:david). If you don't want to migrate your existing + # test cases which use the @david style and don't mind the speed hit (each + # instantiated fixtures translates to a database query per test method), + # then set this back to true. + self.use_instantiated_fixtures = false + + # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. + # + # Note: You'll currently still have to declare fixtures explicitly in integration tests + # -- they do not yet inherit this setting + fixtures :all + + # Add more helper methods to be used by all tests here... + # + def logger + RAILS_DEFAULT_LOGGER + end +end diff --git a/test/unit/community_message_test.rb b/test/unit/community_message_test.rb new file mode 100644 index 0000000..4b543b5 --- /dev/null +++ b/test/unit/community_message_test.rb @@ -0,0 +1,26 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class CommunityMessageTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb new file mode 100644 index 0000000..ef2caf7 --- /dev/null +++ b/test/unit/community_test.rb @@ -0,0 +1,26 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class CommunityTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/event_test.rb b/test/unit/event_test.rb new file mode 100644 index 0000000..7027376 --- /dev/null +++ b/test/unit/event_test.rb @@ -0,0 +1,55 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class EventTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end + + test "generate new created event" do + Event.delete_all + ec = Event.all.count + ev = nil + assert_nothing_raised(Exception) do + ev = Event.make(:event_type_name => ev_types(:created).name, :membership_message => MembershipMessage.find(1)) + end + + assert_nothing_raised(ActiveRecord::RecordNotFound) { ev = Event.find(ev.id) } + assert_equal(1,Event.all.count) + + assert_equal(participants(:ilias_stgt).id, ev.participant_id) + assert_equal(messages(:numlab_ex1).id, ev.message_id) + assert_equal(ev_types(:created).id, ev.ev_type_id) + end + + test "participant deletion" do + Event.delete_all + ev = nil + assert_nothing_raised(Exception) do + ev = Event.make(:event_type_name => ev_types(:created).name, :membership_message => MembershipMessage.find(1)) + end + + assert_nothing_raised(Exception) { participants(:ilias_stgt).destroy } + assert_raise(ActiveRecord::RecordNotFound) { Event.find(ev.id) } # event has to be gone (removed) + assert_equal(0,Event.all.count) # event has to be gone (removed) + end + +end diff --git a/test/unit/helpers/admin/communities_helper_test.rb b/test/unit/helpers/admin/communities_helper_test.rb new file mode 100644 index 0000000..737e688 --- /dev/null +++ b/test/unit/helpers/admin/communities_helper_test.rb @@ -0,0 +1,22 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class Admin::CommunitiesHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/admin/identities_helper_test.rb b/test/unit/helpers/admin/identities_helper_test.rb new file mode 100644 index 0000000..08a245c --- /dev/null +++ b/test/unit/helpers/admin/identities_helper_test.rb @@ -0,0 +1,22 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class Admin::IdentitiesHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/admin/organizations_helper_test.rb b/test/unit/helpers/admin/organizations_helper_test.rb new file mode 100644 index 0000000..c0896fd --- /dev/null +++ b/test/unit/helpers/admin/organizations_helper_test.rb @@ -0,0 +1,22 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class Admin::OrganizationsHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/admin/participants_helper_test.rb b/test/unit/helpers/admin/participants_helper_test.rb new file mode 100644 index 0000000..bd028ca --- /dev/null +++ b/test/unit/helpers/admin/participants_helper_test.rb @@ -0,0 +1,22 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class Admin::ParticipantsHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/admin/ressources_helper_test.rb b/test/unit/helpers/admin/ressources_helper_test.rb new file mode 100644 index 0000000..9ed47e2 --- /dev/null +++ b/test/unit/helpers/admin/ressources_helper_test.rb @@ -0,0 +1,22 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class Admin::RessourcesHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/events_helper_test.rb b/test/unit/helpers/events_helper_test.rb new file mode 100644 index 0000000..4f0612f --- /dev/null +++ b/test/unit/helpers/events_helper_test.rb @@ -0,0 +1,22 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class EventsHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/memberships_helper_test.rb b/test/unit/helpers/memberships_helper_test.rb new file mode 100644 index 0000000..96d054b --- /dev/null +++ b/test/unit/helpers/memberships_helper_test.rb @@ -0,0 +1,22 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class MembershipsHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/messages_helper_test.rb b/test/unit/helpers/messages_helper_test.rb new file mode 100644 index 0000000..b092cf0 --- /dev/null +++ b/test/unit/helpers/messages_helper_test.rb @@ -0,0 +1,22 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class MessagesHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/queue_helper_test.rb b/test/unit/helpers/queue_helper_test.rb new file mode 100644 index 0000000..7c979fd --- /dev/null +++ b/test/unit/helpers/queue_helper_test.rb @@ -0,0 +1,22 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class QueueHelperTest < ActionView::TestCase +end diff --git a/test/unit/membership_message_test.rb b/test/unit/membership_message_test.rb new file mode 100644 index 0000000..aed6982 --- /dev/null +++ b/test/unit/membership_message_test.rb @@ -0,0 +1,36 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class MembershipMessageTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end + + # Only testing for destroy should be sufficient, because updating is + # implemented as first destroying and recreating the membership_messages + test "optimistic locking" do + mm1 = mm2 = nil + assert_nothing_raised(ActiveRecord::RecordNotFound) { mm1 = MembershipMessage.find(1) } + assert_nothing_raised(ActiveRecord::RecordNotFound) { mm2 = MembershipMessage.find(1) } + assert_nothing_raised(Exception) { mm1.destroy } + assert_raise(ActiveRecord::StaleObjectError) { mm2.destroy } + end +end diff --git a/test/unit/message_test.rb b/test/unit/message_test.rb new file mode 100644 index 0000000..0bb7688 --- /dev/null +++ b/test/unit/message_test.rb @@ -0,0 +1,26 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class MessageTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/participant_test.rb b/test/unit/participant_test.rb new file mode 100644 index 0000000..94297c1 --- /dev/null +++ b/test/unit/participant_test.rb @@ -0,0 +1,31 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class ParticipantTest < ActiveSupport::TestCase + +# test "blank participants" do +# [:name, :dns, :email, :organization_id].each do |attrib| +# p= Participant.new(:name=>"freeit",:dns=>"ecs.freeit.de",:email=>"hb7@gmx.net",:description=>nil,:organization_id=>1) +# p[attrib]= nil +# assert !p.valid? +# assert p.errors.invalid?(attrib) +# end +# end +end diff --git a/test/unit/ressource_monitor_test.rb b/test/unit/ressource_monitor_test.rb new file mode 100644 index 0000000..9dc8169 --- /dev/null +++ b/test/unit/ressource_monitor_test.rb @@ -0,0 +1,26 @@ +# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). +# +# This file is part of ECS. +# +# ECS is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# ECS is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with ECS. If not, see <http://www.gnu.org/licenses/>. + + +require 'test_helper' + +class MonitorTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end |